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

[Bug]: Panic occurred when using SWC plugin in development mode #5921

Closed
chenjiahan opened this issue Mar 12, 2024 · 12 comments
Closed

[Bug]: Panic occurred when using SWC plugin in development mode #5921

chenjiahan opened this issue Mar 12, 2024 · 12 comments
Assignees
Labels
team The issue/pr is created by the member of Rspack.

Comments

@chenjiahan
Copy link
Member

System Info

System:
OS: macOS 13.6.3
CPU: (10) arm64 Apple M1 Pro
Memory: 1.03 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Yarn: 1.22.19 - ~/Library/Application Support/fnm/node-versions/v18.19.0/installation/bin/yarn
npm: 10.2.3 - ~/Library/Application Support/fnm/node-versions/v18.19.0/installation/bin/npm
pnpm: 8.15.4 - ~/Library/Application Support/fnm/node-versions/v18.19.0/installation/bin/pnpm
Browsers:
Chrome: 122.0.6261.112
Safari: 16.6
npmPackages:
@rspack/cli: latest => 0.5.7
@rspack/core: latest => 0.5.7

Details

Panic occurred when using SWC plugin in development mode:

image

Rspack config:

const config = {
  mode: "development",
  module: {
    rules: [
      {
        test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
        type: 'javascript/auto',
        use: {
          loader: "builtin:swc-loader",
          options: {
            sourceMap: true,
            jsc: {
              parser: {
                syntax: "typescript",
                jsx: true,
              },
              experimental: {
                plugins: [
                  [
                    "@swc/plugin-remove-console",
                    {
                      exclude: ["error"],
                    },
                  ],
                ],
              },
            },
          },
        },
      },
    ],
  },
};

Reproduce link

https://github.com/chenjiahan/rspack-repro-swc-warn-plugin

Reproduce Steps

  1. pnpm i
  2. pnpm dev:rspack
@chenjiahan chenjiahan added bug Something isn't working pending triage The issue/PR is currently untouched. labels Mar 12, 2024
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Mar 12, 2024
@chenjiahan
Copy link
Member Author

@h-a-n-a cc~

@esturcke
Copy link

Seeing a runtime panic when trying to use https://github.com/kwonoj/swc-plugin-coverage-instrument:

● Client ━━━━━━━━━━━━━━━━━━━━━━━━━ (50%) building /.../node_modules/validator/lib/isFloat.js                                                                                                                  Panic occurred at runtime. Please file an issue on GitHub with the backtrace below: https://github.com/web-infra-dev/rspack/issues
Message:  failed to invoke plugin: failed to invoke plugin on 'Some("/.../src/app/application.tsx")'

Caused by:
    0: failed to invoke `swc-plugin-coverage-instrument` as js transform plugin at swc-plugin-coverage-instrument
    1: RuntimeError: out of bounds memory access
Location: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.272.6/src/plugin.rs:162

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 1: _napi_register_module_v1
    at <unknown source file>
 2: _napi_register_module_v1
    at <unknown source file>
 3: _napi_register_module_v1
    at <unknown source file>
 4: _napi_register_module_v1
    at <unknown source file>
 5: _napi_register_module_v1
    at <unknown source file>
 6: _wasmer_vm_imported_memory32_atomic_notify
    at <unknown source file>
 7: _wasmer_vm_imported_memory32_atomic_notify
    at <unknown source file>
 8: _napi_register_module_v1
    at <unknown source file>
 9: _napi_register_module_v1
    at <unknown source file>
10: _napi_register_module_v1
    at <unknown source file>
11: _napi_register_module_v1
    at <unknown source file>
12: _napi_register_module_v1
    at <unknown source file>
13: _napi_register_module_v1
    at <unknown source file>
14: _napi_register_module_v1
    at <unknown source file>
15: _napi_register_module_v1
    at <unknown source file>
...

@xc2
Copy link
Collaborator

xc2 commented Mar 20, 2024

tracking list of panic cases related to swc-plugins:

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Mar 21, 2024

Thanks for reporting this issue to us.
This happens if the plugin's SWC version not compatible with rspack's. There's an AST breaking change introduced in the latest version of swc. For SWC version in rspack 0.5.8, you may now use plugins of version 1.5.113. We would add some version checks to prevent this and guide user to use the corresponding version.

@esturcke
Copy link

Thanks @h-a-n-a, I'm not clear on what the 1.5.113 version refers to and is this a change the plugin maintainers would need to make?

@huhuaaa
Copy link

huhuaaa commented Mar 21, 2024

@h-a-n-a I have a similar problem. If using other plugins like swc-plugin-auto-css-modules, how do I choose which version to use? Is there any corresponding guidance for the swc version used by rspack?

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Mar 21, 2024

Thanks @h-a-n-a, I'm not clear on what the 1.5.113 version refers to and is this a change the plugin maintainers would need to make?

Thanks for reaching out. It's the version of official plugins provided by swc. For current Rspack version v0.5.8, If It's provided by the third party author, You have to check if the crate swc_core version of that wasm plugin is between 0.88.x ~ 0.89.x.

The biggest difference between @swc/core (the npm package), which is used with swc-loader and builtin:swc-loader is the prior option allows you to switch the suitable @swc/core version, however the latter one doesn't.

@esturcke
Copy link

Ok, so for swc-plugin-coverage-instrument

swc_core           = { version = "0.90.7" }

So that means I would need to wait for an rspack update to use that plugin because there's an API breaking change in SWC?

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Mar 21, 2024

Ok, so for swc-plugin-coverage-instrument

swc_core           = { version = "0.90.7" }

So that means I would need to wait for an rspack update to use that plugin because there's an API breaking change in SWC?

Yes, or you can downgrade to plugin of the version within that range.

@esturcke
Copy link

I tried a few versions of swc-plugin-coverage-instrument but they seem to all cause an error during build. I think I can use babel-plugin-istanbul in the mean time (build time goes up from 15s to 2min :) but we don't need coverage builds as often).

Thanks for all the work on rspack, it's been so much easier to migrate from webpack than vite and performance is incredible.

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Mar 28, 2024

I tried a few versions of swc-plugin-coverage-instrument but they seem to all cause an error during build. I think I can use babel-plugin-istanbul in the mean time (build time goes up from 15s to 2min :) but we don't need coverage builds as often).

Thanks for all the work on rspack, it's been so much easier to migrate from webpack than vite and performance is incredible.

@esturcke We're going to release a minor version of rspack next week. In this version, we bumped swc_core to the latest version, which should support the latest version of swc-plugin-coverage-instrument. #6009.

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Mar 29, 2024

This issue would be closed. For followup plugin selections, please refer to https://swc.rs/docs/plugin/selecting-swc-core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

No branches or pull requests

5 participants