Dynamic imports with module: “commonjs”
swc
now supports transpiling dynamic imports to CommonJS: github.com/swc-project/swc/pull/1028
@swc-node/register
however only sets the jsc.parser.dynamicImport
option for ES2020 modules and newer.
Using @swc-node/register
leads to the following error:
error: import(...) expressions requires `jsc.parser.dynamicImport` to be true
--> /...(file path)...
|
51 | const { GraphQLSchema, GraphQLObjectType } = await import(/* webpackChunkName: "graphql" */ 'graphql');
|
My compilerOptions
:
"allowJs": true,
"target": "esnext",
"lib": ["es6", "dom", "esnext"],
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"resolveJsonModule": true,
Could this also be enabled when targeting CommonJS, or made configurable in the API?
Thanks a lot!
Read more here: Source link