web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.27k stars 540 forks source link

[Bug]: panic during build phase #5611

Closed ilteoood closed 7 months ago

ilteoood commented 7 months ago

System Info

System: OS: macOS 14.3 CPU: (10) arm64 Apple M1 Max Memory: 22.62 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node npm: 10.2.5 - ~/.nvm/versions/node/v20.10.0/bin/npm pnpm: 8.12.1 - ~/.nvm/versions/node/v20.10.0/bin/pnpm Browsers: Chrome: 121.0.6167.139 Edge: 121.0.2277.98 Safari: 17.3

Details

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 get normal module of container entry (default) [["./company-page",{"name":null,"import":["./src/routes/organizations/organizationId/company/Company"]}]] Location: crates/rspack_core/src/tree_shaking/optimizer.rs:661

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 2: _napi_register_module_v1 at 3: _napi_register_module_v1 at 4: _napi_register_module_v1 at 5: _napi_register_module_v1 at 6: _napi_register_module_v1 at 7: _napi_register_module_v1 at 8: _napi_register_module_v1 at 9: _napi_register_module_v1 at 10: _napi_register_module_v1 at 11: _napi_register_module_v1 at 12: _napi_register_module_v1 at 13: _napi_register_module_v1 at 14: _napi_register_module_v1 at 15: _napi_register_module_v1 at 16: _napi_register_module_v1 at 17: _napi_register_module_v1 at 18: _napi_register_module_v1 at 19: _napi_register_module_v1 at 20: __pthread_joiner_wake at

This is the rspack config:

const path = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')
const {ModuleFederationPlugin} = require('@rspack/core').container
const {
  NativeFederationTypeScriptHost,
  NativeFederationTypeScriptRemote
} = require('@module-federation/native-federation-typescript/rspack')
const {
  NativeFederationTestsHost,
  NativeFederationTestsRemote
} = require('@module-federation/native-federation-tests/rspack')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')

const moduleFederationConfigBuilder = require('./module-federation.config')

module.exports = (env, argv) => {
  const isProduction = argv.mode === 'production'
  const moduleFederationConfig = moduleFederationConfigBuilder(isProduction)

  const nativeFederationPlugins = [
    NativeFederationTypeScriptHost({moduleFederationConfig}),
    NativeFederationTypeScriptRemote({moduleFederationConfig}),
    NativeFederationTestsHost({moduleFederationConfig}),
    NativeFederationTestsRemote({moduleFederationConfig})
  ]

  return {
    entry: './src/index',
    cache: false,
    mode: 'development',
    devtool: 'source-map',
    output: {
      publicPath: 'auto',
      clean: true
    },
    devServer: {
      port: 8082,
      historyApiFallback: true,
      open: true,
      hot: true,
      static: {
        directory: path.join(__dirname, 'dist')
      },
      headers: {
        'Access-Control-Allow-Origin': '*'
      },
      proxy: {
        '/bv/api/v1/': {
          pathRewrite: {'^/bv/api/v1': ''},
          target: 'http://127.0.0.1:4010'
        }
      },
      liveReload: true
    },
    module: {
      rules: [
        {
          test: /\.(js|jsx|ts|tsx)$/,
          exclude: [/node_modules/],
          loader: 'builtin:swc-loader',
          options: {
            sourceMap: true,
            jsc: {
              parser: {
                syntax: 'typescript'
              }
            }
          },
          type: 'javascript/auto'
        },
        {
          test: /\.svg/,
          type: 'asset/inline'
        }
      ]
    },
    plugins: [
      new ModuleFederationPlugin(moduleFederationConfig),
      ...(isProduction ? [] : nativeFederationPlugins),
      new HtmlWebpackPlugin({template: './public/index.html'}),
      new ForkTsCheckerWebpackPlugin({
        typescript: {
          configFile: 'tsconfig.build.json',
          diagnosticOptions: {
            semantic: true,
            syntactic: true
          },
          mode: 'write-references'
        }
      })
    ]
  }
}

Reproduce link

https://github.com/ilteoood/rspack-build-error-repro

Reproduce Steps

Run rspack --mode production

ilteoood commented 7 months ago

it seems that you must configure

    resolve: {
      extensions: ['.ts', '.tsx', '.js', '.d.ts']
    }

to solve this. Maybe a better error message would be enough

IWANABETHATGUY commented 7 months ago

Also, you could enable

  experiments: {
      rspackFuture: {
        newTreeshaking: true
      }
    }

the diagnostics should be more helpful:


ERROR in × Resolve error: Can't resolve './src/index' in '/home/xxx/Documents/rspack/issues/rspack-build-error-repro'

ERROR in container entry
  × Resolve error: Can't resolve './src/routes/organizations/organizationId/company/Company' in '/home/xxxx/Documents/rspack/issues/rspack-build-error-repro'
   ╭────
   ╰────

2 ERRORS in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
IWANABETHATGUY commented 7 months ago

Since the old tree shaking is not compatible with the webpack arch, and it would be deprecated in the future, we don't have plan to improve this.