Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wrong] ESM module type does not support fields from common-js #7963

Closed
patricklafrance opened this issue Sep 17, 2023 · 8 comments
Closed
Labels

Comments

@patricklafrance
Copy link

patricklafrance commented Sep 17, 2023

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/[email protected][email protected][email protected]...(truncated) 71.8 KiB 16 modules
sample/another-remote-module dev:   modules by path ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 5.3 KiB
sample/another-remote-module dev:     ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 1.94 KiB [built] [code generated]
sample/another-remote-module dev:     ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/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/[email protected]/node_modules/html-entities/lib/*.js 81.8 KiB
sample/another-remote-module dev:     ../../node_modules/.pnpm/[email protected]/node_modules/html-entitie...(truncated) 7.91 KiB [built] [code generated]
sample/another-remote-module dev:     ../../node_modules/.pnpm/[email protected]/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/[email protected]/node_modules/ansi-html-comm...(truncated) 4.16 KiB [built] [code generated]
sample/another-remote-module dev:   ../../node_modules/.pnpm/[email protected]/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/[email protected]_@[email protected][email protected]/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/[email protected][email protected][email protected]...(truncated) 71.8 KiB 16 modules
sample/host dev:   modules by path ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 5.3 KiB
sample/host dev:     ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 1.94 KiB [built] [code generated]
sample/host dev:     ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 1.86 KiB [built] [code generated]
sample/host dev:     + 2 modules
sample/host dev:   modules by path ../../node_modules/.pnpm/[email protected]/node_modules/html-entities/lib/*.js 81.8 KiB
sample/host dev:     ../../node_modules/.pnpm/[email protected]/node_modules/html-entitie...(truncated) 7.91 KiB [built] [code generated]
sample/host dev:     ../../node_modules/.pnpm/[email protected]/node_modules/html-entities/lib/name...(truncated) 73 KiB [built] [code generated]
sample/host dev:     ../../node_modules/.pnpm/[email protected]/node_modules/html-entities/lib/nume...(truncated) 339 bytes [built] [code generated]
sample/host dev:     ../../node_modules/.pnpm/[email protected]/node_modules/html-entities/lib/surr...(truncated) 537 bytes [built] [code generated]
sample/host dev:   ../../node_modules/.pnpm/[email protected]/node_modules/ansi-html-comm...(truncated) 4.16 KiB [built] [code generated]
sample/host dev:   ../../node_modules/.pnpm/[email protected]/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/[email protected]_@[email protected][email protected]/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/[email protected][email protected][email protected]...(truncated) 71.8 KiB 16 modules
sample/remote-module dev:   modules by path ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 5.3 KiB
sample/remote-module dev:     ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 1.94 KiB [built] [code generated]
sample/remote-module dev:     ../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_...(truncated) 1.86 KiB [built] [code generated]
sample/remote-module dev:     + 2 modules
sample/remote-module dev:   modules by path ../../node_modules/.pnpm/[email protected]/node_modules/html-entities/lib/*.js 81.8 KiB
sample/remote-module dev:     ../../node_modules/.pnpm/[email protected]/node_modules/html-entitie...(truncated) 7.91 KiB [built] [code generated]
sample/remote-module dev:     ../../node_modules/.pnpm/[email protected]/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/[email protected]/node_modules/ansi-html-comm...(truncated) 4.16 KiB [built] [code generated]
sample/remote-module dev:   ../../node_modules/.pnpm/[email protected]/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/[email protected]_@[email protected][email protected]/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

@kdy1
Copy link
Member

kdy1 commented Sep 17, 2023

strict is not a valid option for ESM, as strict does not have any meaning.
The only option valid for ESM is resolveFull: pool

@kdy1 kdy1 closed this as completed Sep 17, 2023
@kdy1
Copy link
Member

kdy1 commented Sep 17, 2023

https://github.com/swc-project/swc/blob/e7493283120721499751f83d3753f5a3b523a1a3/crates/swc_ecma_transforms_module/src/lib.rs#L24C2-L27

#[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,

@kdy1 kdy1 changed the title With @swc/core v1.3.85 I get the following error: Error: unknown field strict, expected resolveFully [Wrong] ESM module type does not support fields from common-js Sep 17, 2023
@patricklafrance
Copy link
Author

Thank you @kdy1 🙏🏻

What exactly does resolveFully do? I can't find anything on the documentation website.

@marviobezerra
Copy link

I'm also getting this same error with version 1.3.86. What is resolveFully and why do I need it?

@kdy1
Copy link
Member

kdy1 commented Sep 19, 2023

You don't need resolveFully

@kdy1
Copy link
Member

kdy1 commented Sep 19, 2023

Remove wrong fields.

@marviobezerra
Copy link

marviobezerra commented Sep 19, 2023

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
  }
}

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2023

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants