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?