monaco-editor-webpack-plugin

Created on 9 Oct 2019  路  6Comments  路  Source: microsoft/monaco-editor

monaco-editor v0.18.1
npm run project it will be warnings in operation How to resolve this warning

WARNING in ./node_modules/[email protected]@monaco-editor/esm/vs/language/typescript/lib/typescriptServices.js
Module not found: Error: Can't resolve '@microsoft/typescript-etw' in 'D:\Desktop\vue-backend-dev\[email protected]@monaco-editor\esm\vs\language\typescript\lib'
@ ./node_modules/[email protected]@monaco-editor/esm/vs/language/typescript/lib/typescriptServices.js
@ ./node_modules/[email protected]@monaco-editor/esm/vs/language/typescript/tsWorker.js
@ ./node_modules/[email protected]@monaco-editor/esm/vs/language/typescript/ts.worker.js

bug important monaco-typescript webpack

Most helpful comment

This isn't a bug with the webpack plugin, it's an issue with Monaco's (actually monaco-typescript's) current version of typescriptServices.js. Specifically this part:

try {
    etwModule = require("@microsoft/typescript-etw");
} catch (e) {
    etwModule = undefined;
}

Monaco's publishing process is supposed to strip out require calls like this to avoid breaking webpack, but this must be new and they missed it. I submitted a fix here: https://github.com/microsoft/monaco-typescript/pull/49.

Until the fix gets merged and published, for this specific case you can add something like this to your webpack config as a workaround:

externals: { '@microsoft/typescript-etw': 'FakeModule' }

This tells webpack that @microsoft/typescript-etw points to a global called FakeModule and shouldn't be bundled (externals reference). Of course that global doesn't exist and trying to access it will cause an exception at runtime, but that's okay here due to the try/catch wrapper in the original code.

All 6 comments

Also running into this, presumably since upgrading to the latest version of the monaco-editor module.
Note: I'm working on a Fedora machine.

Maybe he need to update the monaco-editor-webpack-plugin plug-in or Or he should adjust v0.18.1 compatibility . if you resolve it please tell me

Same here, with monaco-editor-webpack-plugin v1.7.0, it also doesn't build with webpack in dev mode.
Downgrading to monaco-editor v0.16.2 works (higher versions might also work, didn't try them).
I'm working on macOS Mojave, tried to install @microsoft/typescript-etw' but it's win32 specific.

i'm try to down monaco-editor v0.17.0 . it has no warning.

This isn't a bug with the webpack plugin, it's an issue with Monaco's (actually monaco-typescript's) current version of typescriptServices.js. Specifically this part:

try {
    etwModule = require("@microsoft/typescript-etw");
} catch (e) {
    etwModule = undefined;
}

Monaco's publishing process is supposed to strip out require calls like this to avoid breaking webpack, but this must be new and they missed it. I submitted a fix here: https://github.com/microsoft/monaco-typescript/pull/49.

Until the fix gets merged and published, for this specific case you can add something like this to your webpack config as a workaround:

externals: { '@microsoft/typescript-etw': 'FakeModule' }

This tells webpack that @microsoft/typescript-etw points to a global called FakeModule and shouldn't be bundled (externals reference). Of course that global doesn't exist and trying to access it will cause an exception at runtime, but that's okay here due to the try/catch wrapper in the original code.

Was this page helpful?
0 / 5 - 0 ratings