rspack: [Bug]: Build hangs when using rspack.CssExtractRspackPlugin.loader with builtin:swc-loader set to env.mode: usage

System Info

System: OS: macOS 14.7 CPU: (8) arm64 Apple M2 Memory: 52.23 MB / 24.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 20.17.0 - ~/.nodebrew/current/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 10.8.2 - ~/.nodebrew/current/bin/npm pnpm: 8.15.3 - ~/.nodebrew/current/bin/pnpm bun: 1.0.2 - /opt/homebrew/bin/bun Browsers: Chrome: 130.0.6723.70 Edge: 130.0.2849.56 Safari: 18.0 npmPackages: @rspack/cli: ^1.0.14 => 1.0.14 @rspack/core: ^1.0.14 => 1.0.14

Details

Build hangs when using rspack.CssExtractRspackPlugin.loader with builtin:swc-loader set to env.mode: usage. The build succeeds when env.mode is set to entry.

{
  mode: "development",
  entry: "./src/index.js",
  output: {
    path: "./dist",
  },
  module: {
    rules :[
      {
        test: /\.css$/,
        use: [
          {
            loader: rspack.CssExtractRspackPlugin.loader,
          },
          {
            loader: "css-loader",
          },
        ],
      },
      {
        test: /\.js$/,
        use: {
          loader: "builtin:swc-loader",
          options: {
            jsc: {
              parser: {
                syntax: "ecmascript",
              },
            },
            env: {
              mode: process.env.ENV_MODE, // "entry" or "usage"
              coreJs: require("core-js/package.json").version,
              targets: ["IE 11"],
            },
          },
        },
        type: "javascript/auto"
      },
    ],
  },
  experiments: {
    css: false
  },
  plugins: [
    new rspack.CssExtractRspackPlugin({
      filename: `[name].[chunkhash:10].css`,
    }),
  ],
}

Reproduce link

https://github.com/Thiry1/rspack-bug-repro/commit/ae6055b36cf62e19861a32023a1d663cbfe37f36

Reproduce Steps

  1. clone repro repo
  2. git switch swc-mode
  3. npm i
  4. npm run build:mode:usage

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

We’ll fix this soon, sorry for the delay

I’ve found that we can avoid the issue by setting isModule to “unknown”.

Yeah, should keep module’s format as is

I think it is no related to this issue.

I guess the potential cause of it is that the core-js code is injected to core-js itself, thus created a cyclic dependencies, $ is not initialized when executing.

You can try avoid using swc-loader for node_modules/core-js package

I’ve found that we can avoid the issue by setting isModule to “unknown”.

{
  loader: "builtin:swc-loader",
  options: {
+    isModule: "unknown",
  }
}

I’m fixing it, during this time, you can ignore javascript in core-js package to escape this issue