-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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] Cannot read properties of undefined (reading 'toUrl') #4739
Comments
I used Vite, but it doesn't work. |
Same issue in rspack. self.MonacoEnvironment = {
getWorker: function (moduleId, label) {
if (label === 'json') {
return new Worker(
new URL(
'monaco-editor/esm/vs/language/json/json.worker',
import.meta.url
)
);
}
if (label === 'css' || label === 'scss' || label === 'less') {
return new Worker(
new URL('monaco-editor/esm/vs/language/css/css.worker', import.meta.url)
);
}
if (label === 'html' || label === 'handlebars' || label === 'razor') {
return new Worker(
new URL(
'monaco-editor/esm/vs/language/html/html.worker',
import.meta.url
)
);
}
if (label === 'typescript' || label === 'javascript') {
return new Worker(
new URL(
'monaco-editor/esm/vs/language/typescript/ts.worker',
import.meta.url
)
);
}
return new Worker(
new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url)
);
},
}; |
I tried downgrading to 0.50.0 and it solved. |
Using vite, could not get it to work. Any solutions so far? |
For me it worked after I packed the code ( import "./monacoWorker";
import * as monaco from 'monaco-editor';
const editor = monaco.editor.create(/* ... */); |
importing separately solves the errors for me. import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution';
import 'monaco-editor/esm/vs/basic-languages/html/html.contribution';
import 'monaco-editor/esm/vs/basic-languages/css/css.contribution';
import 'monaco-editor/esm/vs/basic-languages/xml/xml.contribution';
import 'monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution';
import 'monaco-editor/esm/vs/basic-languages/markdown/markdown.contribution';
import 'monaco-editor/esm/vs/language/json/monaco.contribution.js'; |
I ended up using this for vite from the https://www.npmjs.com/package/@monaco-editor/react readme
|
` self.MonacoEnvironment = { const editor = monaco.editor.create(/* ... */); |
I tried using version 0.50.0 and finally solved the problem. First, 0.52.0 -> 0.50.0 Second, import worker file from cdn like unpkg export const ensureMonacoEnvironment = () => {
self.MonacoEnvironment = {
getWorkerUrl: () =>
`data:text/javascript;charset=utf-8,${encodeURIComponent(`
self.MonacoEnvironment = {
baseUrl: 'https://unpkg.com/[email protected]/min/'
};
importScripts('https://unpkg.com/[email protected]/min/vs/base/worker/workerMain.js');`)}`,
};
}; Import this function in the file using the monaco editor and execute it. Now I have no error |
Reproducible in vscode.dev or in VS Code Desktop?
Reproducible in the monaco editor playground?
Monaco Editor Playground Link
why
Monaco Editor Playground Code
No response
Reproduction Steps
No response
Actual (Problematic) Behavior
No response
Expected Behavior
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: