monaco-languageclient: Runtime warning about "Could not create web worker(s)..."
Full warnings I get are
Could not create web worker(s). Falling back to loading web worker code in main thread, which might cause UI freezes. Please see https://github.com/microsoft/monaco-editor#faq
I don’t think I’m getting the UI freezes it mentions, but the warning appeared when I changed from using the buildWorkerDefinition() method from the monaco-editor-workers package to using the new useWorkerFactory method of building/initializing workers. Or it could be from updating the monaco-languageclient packages, I’m not sure, but I don’t think I can use monaco-editor-workers with the newer monaco-languageclient packages.
I’m using the monaco-editor-wrapper, but the warnings also appear in a branch I have where I’m not using the wrapper, so it doesn’t appear to be related to that.
It seems to be only about the simpleWorker, and it happens even if I don’t include the 'TextEditorWorker' and 'TextMateWorker' functions under workerLoaders for the useWorkerFactory() call like it is here
I’m using Angular and Webpack, and these versions of monaco packages: monaco-editor: 0.52.2, monaco-editor-wrapper: 6.2.5 monaco-languageclient: 9.2.5
A bit more from the console log in case it’s relevant:
My code where I’m using monaco editor can be seen here
I’ll reiterate that I’m not seeing errors or anything breaking that I’m aware of, but I’m guessing it’s not intended.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 35 (10 by maintainers)
@jhk-mjolner I added your solution to the README here. This is not yet on main, but will be soon.
webpack-cli(or webpack will do it for you when you try running this later).bundle-monaco-workers.jsfile with this content:"bundle monaco workers": "webpack --config bundle-monaco-workers.js"npm run 'bundle monaco workers'workerLoadersparameter foruseWorkerFactoryto point to the pre-bundled workers:editor.experimental.asyncTokenizationin the monaco-wrapper config, if you want to use the textmate worker.It should work after that!
@jhk-mjolner you can disable the Textmate Worker by setting
editor.experimental.asyncTokenizationto false: https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/src/bare/client.ts#L24Building worker bundles yourself is pretty straight-forward, see: https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper/build/vite.cssWorker.ts
It is invoked like this: https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper/package.json#L77
I don’t want to expand the worker pre-bundling. My plan was actually to remove it. It could make sense to move the bundling instructions to an new extra package everyone can consume and perform the bundling if needed.
Since I got it working with copying the editorWorker-es.js file, I guess we can close this issue.
maybe you can do something in webpack as we do in esbuild
@jhk-mjolner yes, I will bring back the pre-bundled workers with #863