-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add instructions for integrating ESM version with snowpack #2227
Comments
Do you by any chance get an "Unexpected usage" error? From what I understand this might be broken in ESM #2212 |
Yes! Basically I have this (unnecessary stuff left out for readability) Main application typescript: import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
import 'monaco-editor/esm/vs/editor/editor.worker.js'
import 'monaco-editor/esm/vs/language/typescript/ts.worker.js'
import 'monaco-editor/esm/vs/editor/browser/controller/coreCommands.js';
import 'monaco-editor/esm/vs/editor/contrib/find/findController.js';
import 'monaco-editor/esm/vs/language/typescript/monaco.contribution.js';
import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution.js';
self.MonacoEnvironment = {
getWorkerUrl: function (moduleId, label) {
if (label === 'typescript' || label === 'javascript') {
return 'web_modules/monaco-editor/esm/vs/language/typescript/ts.worker.js';
}
return 'web_modules/monaco-editor/esm/vs/editor/editor.worker.js';
}
} By just doing an import without using, Snowpack makes the module available under Not sure wether to solve this in my JS-file, Snowpack or Monaco.. |
Steps to reproduce:
edit: src/index.ts (here I am defining getWorker instead of getWorkerUrl to set worker type) import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js'
import 'monaco-editor/esm/vs/editor/editor.worker.js'
import 'monaco-editor/esm/vs/language/typescript/ts.worker.js'
import 'monaco-editor/esm/vs/language/typescript/monaco.contribution.js';
import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution.js';
(self as any).MonacoEnvironment = {
getWorker: function(moduleId:string, label:string) {
console.log("Getting worker", moduleId, label)
if (['javascript', 'typescript'].includes(label)) {
return new Worker('web_modules/monaco-editor/esm/vs/language/typescript/ts.worker.js', {
type: 'module'
})
}
else {
return new Worker('web_modules/monaco-editor/esm/vs/editor/editor.worker.js', {
type: 'module'
})
}
}
}
const app = document.getElementById('app')
if (app !== null) {
monaco.editor.create(app, {
value: 'function x():void {console.log("Hello world!"); }',
language: 'typescript'
})
} edit: public/index.html <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Snowpack App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="module" src="/_dist_/index.js"></script>
<main id="app" style="width:800px; height:600px;"></main>
</body>
</html> And then run with |
@jesperp I am doing the same exact thing so let us know if you found a solution. |
I have just tried the sample from #2227 (comment) and it works for me (I just added one more import to |
@alexdima Thanks for your comment! Could you add your full working example? I tried adding just editor.worker.js:1 |
I am struggling to get this to work well with a snowpack + Svelte application. Been trying the past three days but keep running into worker related issues. I'm not even able to get the AMD version ( The furthest I got was based off this working gist, but I have not been able to extend that config to support Svelte. HTH |
I gave it another try, starting from The See the readme here for more details https://github.com/wires/debugging-snowpack-svelte-monaco |
Ha, okay, managed to get this to work, the problem was I wasn't referencing the modules. See the updated readmed here for details https://github.com/wires/debugging-snowpack-svelte-monaco |
@wires I don't suppose you've managed to get this working with Snowpack 3.x? |
Here is my attempt to work with Snowpack 3.x. https://github.com/luma-dev/alt-json It bundles worker js files into single file before the snowpack compilation with esbuild. It really compiles fast so you wouldn't feel any stresses in development. Even if using esbuild, Snowpack is still necessary to treat css and font assets files imported in Main point is that Snowpack v3.x is exposing local |
I think the example in #2605 solves this issue. |
Can we have instructions on how to integrate the ESM version of Monaco with Snowpack?
As in here:
https://github.com/microsoft/monaco-editor/blob/master/docs/integrate-esm.md
I'm currently trying different configurations and all seems to work except when workers are created.
If any one has a simple snowpack setup to share I can try it and have a PR to update the docs
The text was updated successfully, but these errors were encountered: