79571364

Date: 2025-04-13 08:58:21
Score: 4
Natty: 4.5
Report link

I also encountered the same problem
The only thing I can do is ignore this warning in rsbuild.config.ts

export default defineConfig({
  plugins: [pluginVue()],
  source: {
    ...
  },
  tools: {
    rspack:{
      ignoreWarnings: [/Critical dependency: require function is used in a way in which dependencies cannot be statically extracted/],
    }
  }

Besides, I also saw another solution↓

https://juejin.cn/post/7454129441716207625

tools: {
  rspack: (config, {rspack}) => {
    config.cache = true;
    config.plugins.push(
      /**
       * 关闭警告:
       * public/tools/regulex中存在动态require
       * Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
       */
      new rspack.ContextReplacementPlugin(/require\(\[".*"\]\)/, resolve('public'))
    );
  }
}

Does anyone know how to use it correctly?

Reasons:
  • RegEx Blacklisted phrase (2): Does anyone know
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Casey Fu