Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] - monaco-editor-webpack-plugin fails to load workers cross-origin (esm) #4741

Open
2 tasks done
RoccoC opened this issue Nov 5, 2024 · 0 comments
Open
2 tasks done

Comments

@RoccoC
Copy link

RoccoC commented Nov 5, 2024

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

N/A

Monaco Editor Playground Code

N/A

Reproduction Steps

In order to repro, you'll need a project depending on monaco-editor@>=0.52.0 and [email protected]. The plugin should be configured to load the workers from a different origin than the host.

Actual (Problematic) Behavior

I'm running into an issue in my project after upgrading to [email protected] where the language workers fail to load:

Image

This appears to be caused by the monaco-editor-webpack-plugin, which falls back to using importScripts() when loading these workers cross-origin (in my case, the host origin is localhost:8100, and scripts are served by webpack-dev-server on localhost:8105). importScripts() is only supported for "classic" workers and fails when workers are initialized with type: "module" (https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts#typeerror).

Looks like this was caused by recent changes to the monaco-editor core as part of the ESM migration (here), where workers are now instantiated as module workers.

I believe the fix for this is to update the webpack plugin's getWorkerUrl function (here) to support ESM environments.

Expected Behavior

The worker should successfully load and not result in a TypeError.

Additional Context

I've raised #4742 to update the plugin to support ESM workers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant