-
-
Notifications
You must be signed in to change notification settings - Fork 197
Runtime warning about "Could not create web worker(s)..." #853
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Had this too. Once I changed the useWorkerFactory to use module paths that can be resolved, it worked for me |
Could you expand on that? What did you change more precisely, and was it with angular and/or webpack? I've tried messing around with webpack config and aliases, and changing the paths in the |
Due to the way we bundle the url that was passed / calculated was wrong. Then the worker creation failed I debugged to to find out the url it was requesting and then figured out my app does not deliver it due to the way we bundle |
Okay. I'll try looking further into that. Thanks. Do you remember if there was any particular piece of documentation for webpack (or other) that helped you? Or was it just about finding what the browser requests, and where webpack (or your bundler) puts the files, and making them match? |
yes i debugged the url, and then checked where it actually lands, and then passed the correct url |
Hmm, as far as I can tell, it resolves correctly. export * from '@codingame/monaco-vscode-api/workers/editor.worker'; And the So URLs not resolving might not be my issue... |
It's weird. It appears in the network tab, but as 'pending' and with 0 B transferred, but if I doubleclick it, I can get the content in a new tab with no problem. Only thing I can think of now is that something in the headers, that isn't present when loading it in a new tab, is causing the server not to respond... |
the -es.js file seems self contained the other one just does |
Hmm, I don't have a -es.js file in Now I tried using the |
Hi @jhk-mjolner I just pushed an update to our verification examples including the webpack one (after x.3.0 release). There it works. Please, take a look at the webpack config and especially the worker related things: And very important: Do not install the original You can even remove import * as monaco from '@codingame/monaco-vscode-editor-api'; |
Thanks. I've uninstalled the In the verify/webpack project, I noticed that the loaded worker js file is a clearly webpack bundled file called Except for occasionally breaking things more, the changes I tried with the webpack config didn't change that it was output and fetched as an untransformed I don't know why webpack does that wrong, or how to change it. |
@jhk-mjolner the one thing I can add here is that I have experienced that custom webpack used by ng behaves differently then direct webpack and that may explain your observation. |
Hmm. With the latest version of the codingame packages I cannot find editorWorker-es.js |
solved it by bundling myself
|
@cdietrich I dropped those pre-bundled versions. It was a helpful in the past, but it is better to define something on user level especially with regard to local bundling. |
I've now tried creating a new empty Angular project, installed and used It seems my next option is to manually build the workers in a separate step, as @cdietrich is doing. Though I'm not sure how complicated it's going to be, seeing that I'm not fully controlling webpack, just providing extra configuration, and not using esbuild like it seems @cdietrich is doing. @kaisalmen, would it be possible (and simple) to bring the pre-bundled versions back just to support angular with webpack? User-bundled workers can still be the suggestion and recommendation, but currently things are broken for angular both with webpack and with esbuild. Maybe pre-bundled workers could be an easy way to make it work at least for angular with webpack? |
@jhk-mjolner yes, I will bring back the pre-bundled workers with #863 |
I saw that #863 is merged, and a x.4.0 versions have been released. Is the pre-bundling not included in x.4.0, are the pre-bundled versions available at other paths, or am I misunderstanding something? |
did you see ./node_modules/monaco-editor-wrapper/dist/workers/editorWorker-es.js |
No, I hadn't found that. Thanks! 🙂 I'm trying to import it like
Which it obviously can't import in the browser. I tried messing around with the worker and module related webpack configurations again, but nothing I try seem to fix it. |
Thanks for the suggestion! I'm not happy about having to do the manual step of copying it when the |
maybe you can do something in webpack as we do in esbuild
|
Yeah, I was trying something like that with 'assets' in edit: for future reference, I got it working with the following glob in
and imported as |
Since I got it working with copying the editorWorker-es.js file, I guess we can close this issue. |
I'm having the same problem again with the TextMateWorker now that I'm making a TextMate grammar to color the code. Is pre-bundling the TextMateWorker an option? Do you have new ideas about what can be done with Angular/Webpack to make it bundle it properly? Or should I perhaps just use it with the runtime warning, but seemingly working, as it is now? |
Maybe someone can tell me what the worker is supposed to do, so I can check if that feature is broken for me. |
@jhk-mjolner you can disable the Textmate Worker by setting Building worker bundles yourself is pretty straight-forward, see: It is invoked like this: 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. |
Thanks! I'll into it further next week, but I think it still tries to load the TextMate Worker even with I'll look further into whether I can pre-bundle the workers myself with webpack as well, but I was hoping to move to esbuild when you or CGNoir get that working, and hopefully have automatic worker bundling working with that. I'll close the issue again now, as I don't think you need to do more. |
You were right about it not trying to load the textmate worker when I did look into pre-bundling with webpack and I think I got it all working! So you can remove the pre-bundling from your side, when you want. I'll add a comment in a sec with instructions for others in my situation. Feel free to point others to it, or copy and modify it however you want. |
// solve: __dirname is not defined in ES module scope
import {fileURLToPath} from 'url';
import {dirname, resolve} from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default {
entry: {
editor: './node_modules/@codingame/monaco-vscode-editor-api/esm/vs/editor/editor.worker.js',
textmate: './node_modules/@codingame/monaco-vscode-textmate-service-override/worker.js',
},
output: {
filename: '[name].js',
path: resolve(__dirname, './src/assets/monaco-workers'),
chunkLoading: false, // if this is true (default), webpack will produce code trying to access global `document` variable for the textmate worker, which will fail at runtime due to being a worker
},
mode: 'production',
performance: {
hints: false,
},
};
'TextEditorWorker': () => new Worker('/assets/monaco-workers/editor.js', {type: 'module'}),
'TextMateWorker': () => new Worker('/assets/monaco-workers/textmate.js', {type: 'module'}),
It should work after that! |
@jhk-mjolner thank you. I will add this to the documentation. |
@jhk-mjolner I added your solution to the README here. This is not yet on main, but will be soon. |
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 themonaco-editor-workers
package to using the newuseWorkerFactory
method of building/initializing workers. Or it could be from updating themonaco-languageclient
packages, I'm not sure, but I don't think I can usemonaco-editor-workers
with the newermonaco-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 underworkerLoaders
for theuseWorkerFactory()
call like it is hereI'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.
The text was updated successfully, but these errors were encountered: