monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] v0.51.0 breaks for browser based imports

Open tobiu opened this issue 1 year ago • 13 comments

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?

Monaco Editor Playground Link

No response

Monaco Editor Playground Code

No response

Reproduction Steps

upgrade from v0.50.0 to v0.51.0

Actual (Problematic) Behavior

v0.50.0 was including the script: editor/editor.main.nls.js.

this silently got removed in v0.51.0 without getting mentioned inside the release log: https://github.com/microsoft/monaco-editor/commit/e52ff427290808dff6809b3f77866ae7a62a119b

after removing the script as well inside the Neo.mjs env, i encountered several errors and warnings: Screenshot 2024-08-26 at 20 41 32

Expected Behavior

there should be no undocumented breaking changes in minor versions.

Additional Context

cross-reference ticket: https://github.com/neomjs/neo/issues/5822

tobiu avatar Aug 26 '24 18:08 tobiu

This is because the blob context cannot load relative urls. @bpasero as discussed, we should probably make these URLs absolute.

hediet avatar Aug 29 '24 15:08 hediet

i looked a bit more into it. using v0.50.0: Screenshot 2024-08-31 at 11 54 29

i assume the monaco worker name is "javascript". we do not see the neo workers here, since we are inside the shared workers mode of the framework.

what definitely changed with v0.51.0 is that monaco is trying to use importScripts. now this is a problem, since we are inside a JS module scope. in this context, monaco should stick to use import, since importScripts can not work.

makes sense?

off topic: we have the multi-window support (without a native shell) fully working inside the Neo.mjs framework. so we can move the preview mode (mounting the widgets which get described inside the monaco editor) into different browser windows. we could also move multiple monaco editor instances into multiple windows, and they can still communicate. if it is a backlog item for you to also support multi-window, we can connect. you could save a lot of time with looking into the neo source code (MIT licensed). Screenshot 2024-08-31 at 11 59 04

tobiu avatar Aug 31 '24 10:08 tobiu

Potential fix: https://github.com/microsoft/vscode/commit/634933e5d57b1e4d62e5df92b42c9024ba232707

bpasero avatar Sep 03 '24 15:09 bpasero

I just tried it out in my use-case with v0.52.0. Not sure if the hotfix-candidate was already in there.

If so, it did not work: Screenshot 2024-09-21 at 23 27 32

As mentioned inside my last comment: I really think the main issue is that importScripts() can not work inside a JavaScript module based setting. So we need dynamic imports => import() instead for this context. I recommend to take a closer look into your isESM check, since it is already there, just not hitting true.

You are welcome to ping me, in case you need help. We could do a quick screen-sharing session to enable you to run my use-case locally.

tobiu avatar Sep 21 '24 21:09 tobiu

Same error using monaco-editor-webpack-plugin 7.1.0 under monaco 0.52.0 @aiday-mar The task goes into the backlog? How are we supposed to handle this? I don't use any overrides about worker or url's, for my purposes, this is a blocker bug.

MaxenceMouchard avatar Sep 30 '24 13:09 MaxenceMouchard

Same Issue here. I'm blocked from use the latest versions due to this.

JMGomes avatar Oct 05 '24 22:10 JMGomes

We in the Effect-TS org have also started experimenting with re-writing our playground (which leverages Monaco) to be bundled with Vite instead of dynamically loaded from a CDN.

While we are able to successfully run our playground, the issue that @tobiu described in great detail with import vs importScripts is blocking us from being able to register a custom TS worker with Monaco client side.

IMax153 avatar Oct 17 '24 15:10 IMax153

@aiday-mar I notice this issue did move to the backlog, we had to downgrade to Monaco v0.50 to prevent this error in the meantime. Is there any way to prevent this error or suggested work around to allow for an upgrade?

GKersten avatar Oct 25 '24 11:10 GKersten

I feel this issue is also related to the issue I am facing when trying to upgrade from 0.43.0 to 0.52.0 in my browser extension. I get errors like below, not exactly sure, but could it be Manifest v3 does not allow loading script with the workerMain.js#javascript syntax. Trying to modify the content security policy does not work, as that does not allow loosening the setting like object-src 'self';

Refused to load the script 'chrome-extension://iimpebfldpbfipbodemijjbfblmkhoeh/js/monaco/vs/base/worker/workerMain.js#javascript' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' ". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback

And

Refused to load the script 'chrome-extension://iimpebfldpbfipbodemijjbfblmkhoeh/js/monaco/vs/base/worker/workerMain.js#javascript' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:*". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

arnoudkooi avatar Oct 26 '24 20:10 arnoudkooi

Hello, any update? I also can't upgrade to latest.

straakaa avatar Nov 15 '24 12:11 straakaa

Same problem with 0.52.0

x-etienne avatar Nov 28 '24 06:11 x-etienne

I would add that your Monaco Editor playground is also affected by this bug ... https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.0#example-creating-the-editor-hello-world

Image

MaxenceMouchard avatar Dec 02 '24 16:12 MaxenceMouchard