microsoft / monaco-editor-webpack-plugin

Moved to https://github.com/microsoft/monaco-editor
483 stars 99 forks source link

trouble with getWorkerUrl and contenthash in filename #107

Closed theoephraim closed 4 years ago

theoephraim commented 4 years ago

From the examples, it seems setting things up with defaults, everything should just work. If I do that, I get the following error: Could not create web worker(s). Falling back to loading web worker code in main thread

While annoying, this is fixable by defining the getWorkerUrl function.

self.MonacoEnvironment = {
  getWorkerUrl: function(moduleId, label) {
    const workerName = {
      json: 'json',
      typescript: 'ts',
      javascript: 'ts',
    }[label]
    return `/${workerName || 'editor'}.worker.js`
  },
}

Easy enough, but if I want to include a content hash in the worker url (for example setting filename: '[name].worker.[contenthash:8].js' then I have no easyway to get that hash to use in the above function.

Is this expected behaviour? Should this just magically work without defining getWorkerUrl?

theoephraim commented 4 years ago

after lots of struggling, I read more of this source code and realized it was because I had self.MonacoEnvironment = {} (with the commented out getWorkerUrl inside it.

Perhaps a warning could be helpful, or loading in the existing MonacoEnvironment if it exists and overwriting it?