Giter Club home page Giter Club logo

Comments (2)

remcohaszing avatar remcohaszing commented on August 22, 2024

I’m not familiar with worker-plugin. I think the following should help you troubleshoot:

  • Could you verify yamlWorkerUrl is defined by logging it to the console?
  • Is worker-plugin configured in your webpack configuration?
  • No only monaco-yaml needs to be handled by MonacoEnvironment.getWorkerUrl(), but also any other workers created by Monaco.
    https://github.com/pengx17/monaco-yaml/blob/090302534ae205d3a7163375bf211be5e8dd5eda/examples/webpack/src/index.js#L10-L17
    In your case this should be something like:
    import editorWorkerUrl from 'worker-plugin/loader?name=yaml&esModule!onaco-editor/esm/vs/editor/editor.worker';
    import yamlWorkerUrl from 'worker-plugin/loader?name=yaml&esModule!monaco-yaml/lib/esm/yaml.worker';
    
    window.MonacoEnvironment = {
      getWorkerUrl(moduleId, label) {
        if (label === 'yaml') {
          return yamlWorkerUrl;
        }
        return editorWorkerUrl;
      }
    };

One additional tip: If you import 'monaco-editor' to get all features, you may as well import { editor } from 'monaco-editor' instead of from monaco-editor/esm/vs/editor/editor.api.

from monaco-yaml.

remcohaszing avatar remcohaszing commented on August 22, 2024

I’m going to close this issue, because Webpack 5 supports web workers out of the box without the need for any special loaders or plugins. Please see the updated example.

window.MonacoEnvironment = {
getWorkerUrl(moduleId, label) {
switch (label) {
case 'css':
return new Worker(new URL('monaco-editor/esm/vs/language/css/css.worker', import.meta.url));
case 'editorWorkerService':
return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
case 'json':
return new Worker(
new URL('monaco-editor/esm/vs/language/json/json.worker', import.meta.url),
);
case 'yaml':
return new Worker(new URL('monaco-yaml/lib/esm/yaml.worker', import.meta.url));
default:
throw new Error(`Unknown label ${label}`);
}
},
};

from monaco-yaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.