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

Support loading ESM workers natively as module Workers #2795

Open
dmnsgn opened this issue Nov 26, 2021 · 2 comments
Open

Support loading ESM workers natively as module Workers #2795

dmnsgn opened this issue Nov 26, 2021 · 2 comments
Labels
ESM ECMAScript modules feature-request Request for new features or functionality

Comments

@dmnsgn
Copy link

dmnsgn commented Nov 26, 2021

Bug/Feature request

I aware that this package currently doesn't support a fully native ESM module because it contains .css/.ttf imports.

The css imports might eventually be okay with CSS module scripts:

import sheet from './styles.css' assert { type: 'css' };

There will still be an issue with how the workers are loaded. Since the monaco-editor/esm/vs/language/typescript/ts.worker.js and monaco-editor/esm/vs/editor/editor.worker.js are ESM modules (they contain imports), they will need to be imported as module Workers:

const editorWorker = new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url), {
  type: 'module'
});

The editor Worker imports monaco-editor/esm/vs/editor/common/services/editorSimpleWorker.js which contains a typeof importScripts check but "the old importScripts() method is not available within module workers"; it will throw:

Uncaught TypeError: Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts().

(as discovered trying to load workers directly with webpack target esm).

So the worker should use import instead of importScripts or be self-contained classic workers.

Related issues:

ESM with Vanilla JS:
#2335

ES Modules (vs Webpack):
#949

ESM and CSS loading:
#886

@alexdima alexdima added the ESM ECMAScript modules label Nov 30, 2021
@hediet hediet added the feature-request Request for new features or functionality label Dec 9, 2021
@dmnsgn
Copy link
Author

dmnsgn commented Jan 7, 2022

Alternatively (and probably best until "module Worker" support is better), the workers should be standalone bundled eg. not contain ESM import/export. @alexdima is that something the new ESBuild usage could help with?

@songzhonghuasongzhonghua

same question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ESM ECMAScript modules feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants