[Wrong] ESM module type does not support fields from `common-js`
patricklafrance opened this issue · 8 comments
Describe the bug
With @swc/core v1.3.85 I get the following error:
Error: unknown field `strict`, expected `resolveFully`.
If lower @swc/core version back to 1.3.84, the error goes away.
Full stack:
sample/another-remote-module dev: built modules 178 KiB [built]
sample/another-remote-module dev: modules by path ../../node_modules/.pnpm/webpack-dev-server@4.15.1_webpack-cli@5.1.4_webpack@5.8...(truncated) 71.8 KiB 16 modules
sample/another-remote-module dev: modules by path ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 5.3 KiB
sample/another-remote-module dev: ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 1.94 KiB [built] [code generated]
sample/another-remote-module dev: ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 1.86 KiB [built] [code generated]
sample/another-remote-module dev: + 2 modules
sample/another-remote-module dev: modules by path ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/*.js 81.8 KiB
sample/another-remote-module dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entitie...(truncated) 7.91 KiB [built] [code generated]
sample/another-remote-module dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/name...(truncated) 73 KiB [built] [code generated]
sample/another-remote-module dev: + 2 modules
sample/another-remote-module dev: container entry 42 bytes [built] [code generated]
sample/another-remote-module dev: ./src/register.tsx 39 bytes [built] [code generated] [1 error]
sample/another-remote-module dev: ../../node_modules/.pnpm/ansi-html-community@0.0.8/node_modules/ansi-html-comm...(truncated) 4.16 KiB [built] [code generated]
sample/another-remote-module dev: ../../node_modules/.pnpm/events@3.3.0/node_modules/events/events.js 14.5 KiB [built] [code generated]
sample/another-remote-module dev: ERROR in ./src/register.tsx
sample/another-remote-module dev: Module build failed (from ../../node_modules/.pnpm/swc-loader@0.2.3_@swc+core@1.3.85_webpack@5.88.2/node_modules/swc-loader/src/index.js):
sample/another-remote-module dev: Error: unknown field `strict`, expected `resolveFully` at line 1 column 575
sample/another-remote-module dev: webpack 5.88.2 compiled with 1 error in 585 ms
sample/host dev: asset main.js 579 KiB [emitted] (name: main)
sample/host dev: asset index.html 217 bytes [emitted]
sample/host dev: runtime modules 28.1 KiB 13 modules
sample/host dev: modules by path ../../node_modules/.pnpm/ 178 KiB
sample/host dev: modules by path ../../node_modules/.pnpm/webpack-dev-server@4.15.1_webpack-cli@5.1.4_webpack@5.8...(truncated) 71.8 KiB 16 modules
sample/host dev: modules by path ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 5.3 KiB
sample/host dev: ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 1.94 KiB [built] [code generated]
sample/host dev: ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 1.86 KiB [built] [code generated]
sample/host dev: + 2 modules
sample/host dev: modules by path ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/*.js 81.8 KiB
sample/host dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entitie...(truncated) 7.91 KiB [built] [code generated]
sample/host dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/name...(truncated) 73 KiB [built] [code generated]
sample/host dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/nume...(truncated) 339 bytes [built] [code generated]
sample/host dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/surr...(truncated) 537 bytes [built] [code generated]
sample/host dev: ../../node_modules/.pnpm/ansi-html-community@0.0.8/node_modules/ansi-html-comm...(truncated) 4.16 KiB [built] [code generated]
sample/host dev: ../../node_modules/.pnpm/events@3.3.0/node_modules/events/events.js 14.5 KiB [built] [code generated]
sample/host dev: ./src/index.ts 39 bytes [built] [code generated] [1 error]
sample/host dev: ERROR in ./src/index.ts
sample/host dev: Module build failed (from ../../node_modules/.pnpm/swc-loader@0.2.3_@swc+core@1.3.85_webpack@5.88.2/node_modules/swc-loader/src/index.js):
sample/host dev: Error: unknown field `strict`, expected `resolveFully` at line 1 column 533
sample/host dev: webpack 5.88.2 compiled with 1 error in 733 ms
sample/remote-module dev: asset remoteEntry.js 585 KiB [emitted] (name: remote1)
sample/remote-module dev: asset main.js 580 KiB [emitted] (name: main)
sample/remote-module dev: asset src_register_tsx.js 1.04 KiB [emitted]
sample/remote-module dev: runtime modules 59.3 KiB 28 modules
sample/remote-module dev: built modules 178 KiB [built]
sample/remote-module dev: modules by path ../../node_modules/.pnpm/webpack-dev-server@4.15.1_webpack-cli@5.1.4_webpack@5.8...(truncated) 71.8 KiB 16 modules
sample/remote-module dev: modules by path ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 5.3 KiB
sample/remote-module dev: ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 1.94 KiB [built] [code generated]
sample/remote-module dev: ../../node_modules/.pnpm/webpack@5.88.2_@swc+core@1.3.85_webpack-cli@5.1.4/node_...(truncated) 1.86 KiB [built] [code generated]
sample/remote-module dev: + 2 modules
sample/remote-module dev: modules by path ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/*.js 81.8 KiB
sample/remote-module dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entitie...(truncated) 7.91 KiB [built] [code generated]
sample/remote-module dev: ../../node_modules/.pnpm/html-entities@2.4.0/node_modules/html-entities/lib/name...(truncated) 73 KiB [built] [code generated]
sample/remote-module dev: + 2 modules
sample/remote-module dev: container entry 42 bytes [built] [code generated]
sample/remote-module dev: ./src/register.tsx 39 bytes [built] [code generated] [1 error]
sample/remote-module dev: ../../node_modules/.pnpm/ansi-html-community@0.0.8/node_modules/ansi-html-comm...(truncated) 4.16 KiB [built] [code generated]
sample/remote-module dev: ../../node_modules/.pnpm/events@3.3.0/node_modules/events/events.js 14.5 KiB [built] [code generated]
sample/remote-module dev: ERROR in ./src/register.tsx
sample/remote-module dev: Module build failed (from ../../node_modules/.pnpm/swc-loader@0.2.3_@swc+core@1.3.85_webpack@5.88.2/node_modules/swc-loader/src/index.js):
sample/remote-module dev: Error: unknown field `strict`, expected `resolveFully` at line 1 column 559
sample/remote-module dev: webpack 5.88.2 compiled with 1 error in 678 ms
sample/remote-module dev: <i> [webpack-dev-server] Gracefully shutting down. To force exit, press ^C again. Please wait...
sample/host dev: <i> [webpack-dev-server] Gracefully shutting down. To force exit, press ^C again. Please wait...
sample/another-remote-module dev: <i> [webpack-dev-server] Gracefully shutting down. To force exit, press ^C again. Please wait...
sample/another-remote-module dev: Failed
Input code
The project for which the error is happening is available here: https://github.com/gsoft-inc/wl-squide.
Bump the `@swc/core` version to `1.3.85` for the following projects:
- `sample/another-remote-module`
- `sample/host`
- `sample/remote-module`
Then:
- `pnpm install`
- `pnpm dev-sample`
The error should print in the console.Config
No response
Playground link
No response
SWC Info output
Operating System:
Platform: win32
Arch: x64
Machine Type: x86_64
Version: Windows 10 Enterprise
CPU: (12 cores)
Models: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 20.6.1
npm: N/A
Yarn: N/A
pnpm: 8.7.4
Relevant Packages:
@swc/core: N/A
@swc/helpers: N/A
@swc/types: N/A
typescript: 5.2.2
SWC Config:
output: N/A
.swcrc path: N/A
Next.js info:
output: N/A
Expected behavior
No error.
Actual behavior
No response
Version
1.3.85
Additional context
The code is transpiled with the following stack: webpack 5 -> swc-loader -> swc/core
strict is not a valid option for ESM, as strict does not have any meaning.
The only option valid for ESM is resolveFull: pool
#[serde(default)]
pub allow_top_level_this: bool,
#[serde(default)]
pub strict: bool,
#[serde(default = "default_strict_mode")]
pub strict_mode: bool,
#[serde(default)]
pub lazy: Lazy,
#[serde(default)]
pub import_interop: Option<ImportInterop>,
/// Emits `cjs-module-lexer` annotation
/// `cjs-module-lexer` is used in Node.js core for detecting the named
/// exports available when importing a CJS module into ESM.
/// swc will emit `cjs-module-lexer` detectable annotation with this option
/// enabled.
///
/// Defaults to `true` if import_interop is Node, else `false`
#[serde(default)]
pub export_interop_annotation: Option<bool>,
#[serde(default)]
/// Note: deprecated
pub no_interop: bool,
#[serde(default)]
pub ignore_dynamic: bool,
#[serde(default)]
pub preserve_import_meta: bool,
#[serde(default)]
pub resolve_fully: bool,Thank you @kdy1 🙏🏻
What exactly does resolveFully do? I can't find anything on the documentation website.
I'm also getting this same error with version 1.3.86. What is resolveFully and why do I need it?
You don't need resolveFully
Remove wrong fields.
I don't have this field and it stills complaining about it. Here my .swcrc content and it works fine with 1.3.80.
{
"sourceMaps": true,
"module": {
"type": "nodenext",
"strict": true,
"strictMode": true,
"noInterop": false
},
"jsc": {
"externalHelpers": true,
"target": "es2022",
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true
}
}
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.