Skip to content
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

Unexpected usage at z.loadForeignModule #13

Open
Florian-Schoenherr opened this issue Oct 14, 2020 · 5 comments
Open

Unexpected usage at z.loadForeignModule #13

Florian-Schoenherr opened this issue Oct 14, 2020 · 5 comments

Comments

@Florian-Schoenherr
Copy link

The import from CDN (on README.md) doesn't work, or I'm doing something really wrong.
Everytime I type a letter it throws a new error.
error
I'm using rollup + svelte and can't really import from npm / don't know how.
Tried several ways, only thing working was just putting it into the static folder, but that's pretty slow and hacky.
So the CDN solution would be best.

@thepassle
Copy link

thepassle commented Feb 19, 2021

The problem here is that the required workers arent bundled with your app. If you inspect the network tab in your devtools, you'll see failing requests for /node_modules/@vanillawc/wc-monaco-editor/monaco/workers/json.worker.js. If you're using rollup you can use rollup-plugin-copy to copy along the required workers to your dist folder.

import copy from 'rollup-plugin-copy';

export default {
  /* config etc */
  plugins: [
    copy({
      targets: [{ src: 'node_modules/@vanillawc', dest: 'dist/node_modules' }],
      hook: 'writeBundle'
    })
  ]
}

It may be worth making a note of this in the docs, the Unexpected usage error from Monaco isn't very clear as to whats going on.

@Florian-Schoenherr
Copy link
Author

@thepassle Thank you so much! We just abandoned Monaco for now, but this should help some people.
I hope either this or some other version of a monaco web component will be available and maintained sometime soon :)
Maybe Microsoft will do it, would make sense.

@evanplaice
Copy link
Member

@thepassle Thanks, I'll make a note of this in the documentation, I'm thinking a FAQ section for common questions.

@Florian-Schoenherr
Copy link
Author

@evanplaice btw. no disrespect to you, I think this here is kinda ambitious! Or I just don't know how it works at all 😄

@evanplaice
Copy link
Member

@Florian-Schoenherr Not sure what you mean by 'ambitious'. This is simply a web component wrapper around Monaco Editor. I have plenty of previous experience working with Monaco so it's not a difficult thing for me.

As to the errors that display in the console. That's specifically a side-effect of running this web component directly from a CDN. Line @thepassle said before, the workers aren't bundled with the main source. This is intentional, to cut down on the sheer mass of code that gets loaded, the workers are side-loaded separately after Monaco Editor initially loads. This isn't a hack, it's the recommended usage as outlined in the official docs.

The current generation of CDNs tend to break this behavior because they run the code through a preprocessing step that breaks import.meta.url or they mangle the directory structure of the code. If you run the wc-monaco-editor sources directly from a web server you will see no such errors.

I need to make a note in the docs that this web component won't work when loaded directly from a CDN (until I find one that doesn't break stuff), otherwise it's 100% functional and ready for use in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants