web-infra-dev / rspack

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

[Bug]: an error occurred when formatting an argument #7596

Open tiny-ant opened 4 weeks ago

tiny-ant commented 4 weeks ago

System Info

System: OS: macOS 13.2.1 CPU: (8) arm64 Apple M1 Memory: 3.15 GB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 20.12.2 - /usr/local/bin/node npm: 10.8.2 - ~/Documents/workspace/inc-cdbi-core-web/node_modules/.bin/npm pnpm: 8.15.4 - ~/.npm-global/bin/pnpm bun: 1.0.6 - ~/.bun/bin/bun Browsers: Chrome: 127.0.6533.120 Safari: 16.3 npmPackages: @rspack/cli: ^0.7.5 => 0.7.5 @rspack/core: ^0.7.5 => 0.7.5 @rspack/plugin-react-refresh: ^1.0.0 => 1.0.0

Details

Message: should print diagnostics: × an error occurred when formatting an argument

Location: crates/rspack_core/src/stats.rs:391

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: _wasmer_vm_imported_memory32_atomic_notify at 7: _wasmer_vm_imported_memory32_atomic_notify at 8: _napi_register_module_v1 at 9: _napi_register_module_v1 at 10: _napi_register_module_v1 at

Reproduce link

No response

Reproduce Steps

my rspack.config.ts file:

import * as path from 'path';
import * as rspack from '@rspack/core';
import * as MonacoEditorWebpackPlugin from 'monaco-editor-webpack-plugin';
import * as CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import * as ReactRefreshPlugin from '@rspack/plugin-react-refresh';
import theme from './theme';
import type { Configuration } from '@rspack/cli';
import type { RspackPluginInstance } from '@rspack/core';

const { NODE_ENV } = process.env;
const isDev = NODE_ENV === 'development';

const entryPath = path.resolve('./src/index.tsx');
const outputPath = path.resolve('./dist');
const publicPath = '/'; // TODO:

const config: Configuration = {
  mode: 'development',
  devtool: 'eval-cheap-module-source-map',
  target: 'web',
  // stats: {
  //   all: true,
  //   children: true,
  // },
  entry: {
    index: entryPath,
  },
  output: {
    path: outputPath,
    pathinfo: false,
    filename: '[name].js',
    chunkFilename: '[name].js',
    publicPath: './',
  },
  // 规划支持中(production 模式 为false, development 模式 为true)
  // cache: true,
  watchOptions: {
    ignored: /node_modules\/!(@cdbi)/,
  },
  resolve: {
    symlinks: false,
    alias: {
      '@': path.resolve('./src'),
      '~': path.resolve('./mobile/src'),
      common: path.resolve('./common'),
      packages: path.resolve('./packages'),
    },
    extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
    // tsConfig: {
    //   configFile: path.resolve('../tsconfig.json'),
    // },
    modules: ['node_modules'],
  },
  devServer: {
    allowedHosts: 'all',
    port: 8000,
    devMiddleware: {
      publicPath,
    },
    proxy: {
        ...
    },
    historyApiFallback: true,
  },
  module: {
    rules: [
      /* config.module.rule('js') */
      {
        test: /\.(js|jsx|ts|tsx|mjs)$/,
        type: 'javascript/auto',
        use: [
          {
            loader: 'builtin:swc-loader',
            /** @type {import('@rspack/core').SwcLoaderOptions} */
            options: {
              env: {
                targets: {
                  chrome: 65,
                },
                coreJs: '3.33.2',
                mode: 'usage',
              },
              jsc: {
                parser: {
                  syntax: 'typescript',
                  tsx: true,
                  dynamicImport: true,
                  decorators: true,
                },
                transform: {
                  react: {
                    runtime: 'automatic',
                    pragma: 'React.createElement',
                    pragmaFrag: 'React.Fragment',
                    throwIfNamespace: true,
                    development: false,
                    // TODO:
                    useBuiltins: false,
                    refresh: isDev,
                  },
                },
              },
              rspackExperiments: {
                import: [
                  {
                    libraryName: 'antd',
                    libraryDirectory: 'es',
                    style: true,
                  },
                ],
              },
            },
          },
        ],
      },
      {
        oneOf: [
          /* config.module.rule('asset').oneOf('image') */
          {
            test: /\.(png|jpe?g|gif|svg|webp|ico)(\?.*)?$/,
            type: 'asset',
          },
          /* config.module.rule('asset').oneOf('fonts') */
          {
            test: /\.(eot|woff|woff2|ttf|otf)(\?.*)?$/,
            type: 'asset/resource',
          },
          /* config.module.rule('asset').oneOf('fallback') */
          {
            type: 'asset/resource',
            exclude: [
              /* handle data: resources */
              /^$/,
              /\.(js|mjs|cjs|jsx|ts|tsx)$/,
              /\.(css|less|sass|scss|stylus)$/,
              /\.html$/,
              /\.json$/,
            ],
          },
        ],
      },
      /* config.module.rule('css') */
      {
        test: /\.(css)(\?.*)?$/,
        use: [
          {
            loader: rspack.CssExtractRspackPlugin.loader,
          },
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              modules: {
                localIdentName: '[local]',
                getLocalIdent() {
                  /* omitted long function */
                },
              },
            },
          },
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                ident: 'postcss',
                plugins: [
                  'postcss-flexbugs-fixes',
                  [
                    'postcss-preset-env',
                    {
                      browsers: ['chrome >= 65'],
                      autoprefixer: {
                        flexbox: 'no-2009',
                      },
                      stage: 3,
                    },
                  ],
                  ['tailwindcss'],
                  ['tailwindcss/nesting'],
                  !isDev ? 'cssnano' : '',
                ],
              },
            },
          },
        ],
      },
      /* config.module.rule('less') */
      {
        test: /\.(less)(\?.*)?$/,
        use: [
          {
            loader: rspack.CssExtractRspackPlugin.loader,
          },
          /* config.module.rule('less').use('css-loader') */
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              modules: {
                localIdentName: '[local]',
                getLocalIdent() {
                  /* omitted long function */
                },
              },
            },
          },
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                ident: 'postcss',
                plugins: [
                  'postcss-flexbugs-fixes',
                  [
                    'postcss-preset-env',
                    {
                      browsers: ['chrome >= 65'],
                      autoprefixer: {
                        flexbox: 'no-2009',
                      },
                      stage: 3,
                    },
                  ],
                  ['tailwindcss'],
                  ['tailwindcss/nesting'],
                  !isDev ? 'cssnano' : '',
                ],
              },
            },
          },
          {
            loader: 'less-loader',
            options: {
              lessOptions: {
                modifyVars: theme,
                javascriptEnabled: true,
                // plugins: [
                //   // TODO: 未生效?
                //   new LessPluginScopeModifyVar([
                //     {
                //       pathReg: /antd\/es\/style\/themes\/(default|variable)/,
                //       modifyVars: {
                //         'ant-prefix': 'ant4',
                //       },
                //     },
                //   ]),
                // ],
                globalVars: {
                  A01: '#3355FF',
                  B01: '#eceff9',
                  xs: '0.1875rem',
                  sm: '0.3125rem',
                  md: '0.5rem',
                  lg: '0.75rem',
                  xl: '1rem',
                  hg: '1.25rem',
                  lhxs: '1.125rem',
                  lhsm: '1.25rem',
                  lhmd: '1.5rem',
                  lhlg: '1.75rem',
                  lhxl: '2rem',
                  rhsm: '2.25rem',
                  rhmd: '2.625rem',
                  rhlg: '3rem',
                },
              },
            },
          },
        ],
      },
    ],
  },
  optimization: {
    minimize: false, // Disabling minification because it takes too long on CI
    minimizer: [new rspack.LightningCssMinimizerRspackPlugin()],
    splitChunks: {
      minSize: 30000,
      maxAsyncRequests: 5,
      automaticNameDelimiter: '_',
      cacheGroups: {
        common: {
          name: 'common',
          test() {
            /* omitted long function */
          },
          priority: 40,
        },
        echarts: {
          name: 'echarts',
          test: /[\\/]node_modules[\\/](echarts|echarts-gl|zrender)/,
          priority: 20,
          enforce: true,
        },
        monacoEditor: {
          name: 'monaco',
          test: /[\\/]node_modules[\\/]monaco-editor/,
          priority: 20,
        },
        x6: {
          name: 'x6',
          test: /[\\/]node_modules[\\/](@antv|jquery)/,
          priority: 20,
        },
        codemirror: {
          name: 'codemirror',
          test: /[\\/]node_modules[\\/](codemirror|@uiw)/,
          priority: 20,
        },
        grapecity: {
          name: 'grapecity',
          test: /[\\/]node_modules[\\/]@grapecity/,
          priority: 20,
        },
        tinymceEditor: {
          name: 'tinymce',
          test: /[\\/]node_modules[\\/](@tinymce|tinymce)/,
          priority: 20,
        },
        tinymcePlugins: {
          name: 'tinymce-plugins',
          test: /[\\/]src[\\/]pages[\\/]XXX[\\/]TextBox[\\/]Tinymce[\\/]plugins/,
          priority: 20,
        },
        defaultVendors: {
          name: 'vendors',
          // TODO:
          // test({ resource }) {
          //   return /[\\/]node_modules[\\/]/.test(resource);
          // },
          priority: 10,
        },
      },
    },
  },
  plugins: [
    new rspack.DefinePlugin({
      NODE_ENV: JSON.stringify(NODE_ENV),
      PLATFORM: '"pc"',
    }),
    new rspack.ProgressPlugin({
      // profile: true,
    }),
    new rspack.HtmlRspackPlugin({
      template: path.resolve('./src/pages/document.html'),
      title: '',
      filename: 'index.html',
      minify: true,
    }),
    new rspack.CopyRspackPlugin({
      patterns: [
        {
          from: path.resolve('./common/assets'),
          to: 'assets',
        },
        {
          from: path.resolve('./public'),
          to: './',
        },
      ],
    }),
    new rspack.CssExtractRspackPlugin({
      filename: '[name].css',
      chunkFilename: '[name].chunk.css',
      // 若某些 CSS 在不同 chunk 中顺序有冲突,是否发出警告。
      // 例如 entryA 引入 a.css 和 b.css,entryB 引入 b.css 和 a.css,a.css 和 b.css 的顺序无法确定
      ignoreOrder: true,
    }),
    // @ts-ignore
    new CaseSensitivePathsPlugin() as RspackPluginInstance,
    // @ts-ignore
    new MonacoEditorWebpackPlugin({
      languages: ['javascript'],
    }) as RspackPluginInstance,
    isDev && new ReactRefreshPlugin(),
  ].filter(Boolean),
};

export default config;

the build script is:

rspack --config build/rspack.config.ts
h-a-n-a commented 3 weeks ago

Cannot produce with a large repo. Would you please provide a minimal repro?

github-actions[bot] commented 3 weeks ago

Hello @tiny-ant, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.