[Bug] 0.56.0 browser-esm-esbuild build error
Reproducible in vscode.dev or in VS Code Desktop?
- [x] Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- [x] Not reproducible in the monaco editor playground
Monaco Editor Playground Link
0.56.0 fails to build. It works fine with 0.55.1
$ npm run build
npm notice run build
npm notice run node ./build.js
Deleted dist
✘ [ERROR] Could not resolve "monaco-editor/esm/vs/editor/editor.main.js"
index.js:1:24:
1 │ import * as monaco from 'monaco-editor/esm/vs/editor/editor.main.js';
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The module "./esm/vs/esm/vs/editor/editor.main.js" was not found on the file
system:
../node_modules/monaco-editor/package.json:45:14:
45 │ "./*.js": "./esm/vs/*.js",
╵ ~~~~~~~~~~~~~~~
Changes to package.json
v0.55.1
"exports": {
".": {
"types": "./esm/vs/editor/editor.main.d.ts",
"import": "./esm/vs/editor/editor.main.js",
"require": "./min/vs/editor/editor.main.js"
},
"./*": "./*"
},
v0.56.0
"exports": {
".": {
"types": "./esm/vs/index.d.ts",
"import": "./esm/vs/index.js",
"require": "./min/vs/index.js"
},
"./*.js": "./esm/vs/*.js",
"./*": "./esm/vs/*.js"
},
Monaco Editor Playground Code
Reproduction Steps
- Install monaco-editor 0.56.0
- Copy browser-esm-esbuild to
/home - Open Terminal
npm run build
Actual (Problematic) Behavior
No response
Expected Behavior
No response
Additional Context
No response
I replaced my
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
import CssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'
import HtmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'
import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
with
import EditorWorker from 'monaco-editor/editor/editor.worker?worker'
import JsonWorker from 'monaco-editor/language/json/json.worker?worker'
import CssWorker from 'monaco-editor/language/css/css.worker?worker'
import HtmlWorker from 'monaco-editor/language/html/html.worker?worker'
import TsWorker from 'monaco-editor/language/typescript/ts.worker?worker'
and it seemed to have resolved my build errors in vite.
Changing the following solves the build issue. https://github.com/microsoft/monaco-editor/blob/4ae151f00c5f05987e70396c484befd734e04744/samples/browser-esm-esbuild/index.js#L1
to:
export * as monaco from 'monaco-editor/editor/editor.main.js';
However, other errors appear when running the bundle (which are not present in 0.55.1):
Content-Security-Policy: The page’s settings blocked a worker script (worker-src) at blob:moz-extension://f5...11/52...22 from being executed because it violates the following directive: “script-src 'self' 'wasm-unsafe-eval'”
Uncaught (in promise) error { target: Worker, isTrusted: true, srcElement: Worker, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 388, … }
The blob content:
/editorWorkerService/globalThis._VSCODE_NLS_MESSAGES = undefined;globalThis._VSCODE_NLS_LANGUAGE = undefined;globalThis._VSCODE_FILE_ROOT = undefined;const ttPolicy = globalThis.trustedTypes?.createPolicy('defaultWorkerFactory', { createScriptURL: value => value });globalThis.workerttPolicy = ttPolicy;try {await import(ttPolicy?.createScriptURL("moz-extension://f5...11/lib/monaco-editor/vs/editor/editor.worker.js#editorWorkerService") ?? "moz-extension://f5...11/lib/monaco-editor/vs/editor/editor.worker.js#editorWorkerService");} catch (err) { console.error("Failed to load worker script for label: editorWorkerService.\nEnsure your bundler properly bundles modules referenced by "new URL('...?esm', import.meta.url)".", err); throw err; }globalThis.postMessage({ type: 'vscode-worker-ready' });/editorWorkerService/
@hediet https://github.com/microsoft/monaco-editor/pull/5155/changes/30f964514f23a1b6e7b972cd80410963da036f31 this commit msg Ensures backwards compatibility indicates the changes should be backward compatible, but currently it is breaking the user space. Could you please review? Thanks!
Hi — thanks for the clear repro, and for confirming this is the official browser-esm-esbuild sample rather than the playground.
0.56.0’s exports map rewrites ./*.js → ./esm/vs/*.js, so monaco-editor/esm/vs/editor/editor.main.js becomes the doubled ./esm/vs/esm/vs/... path in the log. The files are still on disk; only the package specifier changed. That matches the #5155 remap (CHANGELOG lists it as breaking).
I would be happy to open a small PR that updates the sample import to import * as monaco from 'monaco-editor' (the documented full-bundle entry; monaco-editor/editor/editor.main.js also works). build.js worker paths are filesystem-based and should keep working.
@hediet — please shout if you would rather restore a passthrough for the old esm/vs/ specifiers (jxmai’s question on #5155) instead of, or in addition to, the sample update. I can also follow up on the other samples still using monaco-editor/esm/vs/... (webpack workers, parcel, vite-react) if that is useful.
Happy to take whichever approach you prefer. Thanks!