When using monaco-editor with rsbuild
(regardless of whether we incorporate monaco-editor-webpack-plugin or not) we get the following warning during the build process:
⚠ Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
╭─[319:16]
317 │ };
318 │ if (!isESM) {
319 │ require([`${moduleId}`], onModuleCallback, reject);
· ───────
320 │ }
321 │ else {
╰────
All that is required to provoke the warning is to import something from monaco and use it (a mere new monaco.Range()
is sufficient). I understand that the warning is most probably benign but is there a way to prevent or at least silence it?
Steps to reproduce:
- create a simple rsbuild project:
npx create-rsbuild -d monaco-esm-issue -t vanilla
- change into the newly created directory:
cd monaco-esm-issue
- install dependencies:
npm install
- add monaco-editor to the mix:
npm install monaco-editor
- change src/index.js to the content pasted below and run
npm run dev
:
import * as monaco from 'monaco-editor';
new monaco.Range();
As a result, you should now be witnessing the warning described above in the terminal where the npm run dev
has been executed.
When using monaco-editor with rsbuild
(regardless of whether we incorporate monaco-editor-webpack-plugin or not) we get the following warning during the build process:
⚠ Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
╭─[319:16]
317 │ };
318 │ if (!isESM) {
319 │ require([`${moduleId}`], onModuleCallback, reject);
· ───────
320 │ }
321 │ else {
╰────
All that is required to provoke the warning is to import something from monaco and use it (a mere new monaco.Range()
is sufficient). I understand that the warning is most probably benign but is there a way to prevent or at least silence it?
Steps to reproduce:
- create a simple rsbuild project:
npx create-rsbuild -d monaco-esm-issue -t vanilla
- change into the newly created directory:
cd monaco-esm-issue
- install dependencies:
npm install
- add monaco-editor to the mix:
npm install monaco-editor
- change src/index.js to the content pasted below and run
npm run dev
:
import * as monaco from 'monaco-editor';
new monaco.Range();
As a result, you should now be witnessing the warning described above in the terminal where the npm run dev
has been executed.
2 Answers
Reset to default 1You can ignore that warning, but not suppress it. Your bundler is just telling you that its static import analysis cannot handle this kind of import and will not be able to optimize the build (tree-shaking, unused module removal etc.). This happens not only for this code part, but always, when module names are passed in a variable.
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/],
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744798958a4594374.html
评论列表(0条)