Error in Server Side Rendering. Need a valid ESM entry #5205
kingyue737 posted onGitHub
Describe the bug
I tried to introduce G6 in my Nuxt.js project but failed unless transpiling G6. G6 cannot be used in Server Side Rendering, because it does not have a valid ESM entry.
check here https://arethetypeswrong.github.io/?p=%40antv%2Fg6%404.8.23 check also https://publint.dev/@antv/g6@4.8.23
Although G6 contains "module
" in package.json
, Node.js doesn't recognize the "module"
field. Instead, we should use "exports"
to increase compatibility with it. For example:
{
"name":"@antv/g6",
"exports": {
".": {
"import": "./esm/index.mjs", // IMPORTANT, use ".mjs" instead of ".js"
"require": "./lib/index.js"
}
},
}
or with "type": "module"
{
"name":"@antv/g6",
"type":"module",
"exports": {
".": {
"import": "./esm/index.js",
"require": "./lib/index.cjs" // IMPORTANT, use ".cjs" instead of ".js"
}
},
}
I highly recommend to fix it in v5
before stable as it is a breaking change
Refs: https://publint.dev/rules#has_module_but_no_exports https://nuxt.com/docs/guide/concepts/esm#what-are-valid-imports-in-a-nodejs-context
Your Example Website or App
ignore
Steps to Reproduce the Bug or Issue
Load G6 in Node.js
Expected behavior
No error
Screenshots or Videos
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. 91.1]
Additional context
No response