-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
monaco-json doesn't work well with the ESM #1974
Comments
I agree, the esm variants were using the global |
* Format signature and parameter documentation as Markdown * Add support for creating a custom webworker subclass * Make a useful sample * Tidy up * Settle on customTSWorkerFactory * Adds a vfs project * Tightens the public API * update deps * update to typescript@4.0.2 * Add prettier * Run prettier * Use the global `monaco` only in the AMD case (see microsoft/monaco-editor#1974) * Add deprecated diagnostic tag if a symbol is reported as deprecated * Add deprecated tag to suggestion if entry is marked as deprecated * Include tags in documentation string of suggestion items * Align tag representation in suggestion items and hovers * 4.0.0 * small style tweaks * 4.0.1 * improve `.npmignore` * Allows setting lib with shortnames * Remove declare modifiers (microsoft/monaco-editor#2121) * 4.0.2 * Update import TS * Use typescript language for hover tooltip header * update `package-lock.json` * Adopt `async` * Increase `printWidth` * `var` -> `let` * Fixes microsoft/monaco-editor#1937: Remove debugger statement * Fixes microsoft/monaco-editor#1638: Protect against failing `getCodeFixesAtPosition` calls * Fixes microsoft/monaco-editor#1998: make sure to always increase the version number * Adopt latest `monaco-editor-core`, update to TS 4.0.3 * 4.1.0 * Add missing setWorkerOptions * commit generated file * update upstream and enable regex Co-authored-by: Sebastian Pahnke <pahnke.sebastian@gmail.com> Co-authored-by: Orta <git@orta.io> Co-authored-by: Alex Dima <alexdima@microsoft.com> Co-authored-by: Spencer <spencer@sf-n.com>
@alexdima I'm still unable to load the JSON language on demand, the issue seems to be that the language definition and related files directly try to load other parts of Monaco themselves, while I have a separate bundle for it, which I just can't make those files use in any reasonable way. This is in contrast to the basic languages provided which just offer some exports that can be easily integrated with my Monaco bundle. Should I perhaps patch |
Actually since v0.21 some languages are loading large portions of the editor's code just to fetch an enum, e.g. |
For posterity: This webpack plugin made it so that a single instance of Monaco is loaded in my bundles: new webpack.NormalModuleReplacementPlugin (
/\/fillers\/monaco-editor-core\.js$/,
'/Users/fabio/Projects/notable/src/apps/core/lib/monaco/core.ts'
) The content of that That would work for the JSON contributions too, but there's this problematic statement at the start of that file: import '../../editor/editor.api.js'; That would need to be redirected too or patched. |
@fabiospampinato I can take another look, what steps should I try? The idea of these languages is that they are loaded after the editor core has been loaded. So When a model with that particular language id is instantiated, the editor will fire the When I use a webpack config like this one, I can see in the output that the |
monaco-editor version: 0.20.0
Browser: Electron's Chrome 80-something
OS: macOS 10.14.0
I just spent the better part of the afternoon trying to get the JSON language to work with Monaco, now the thing kind of works, but it depends on how I load the JSON language contribution, which in and of itself seems like a problem to me.
First of all for some context I'm creating a separate bundle for Monaco using this Webpack configuration:
The potentially interesting bit of that is the following:
Without these lines Monaco doesn't work at all for me, I don't remember why I added those lines to the configuration, as they don't seem to be mentioned in the sample configurations provided.
Those lines of configurations I think may assign Monaco to "window.monaco".
Getting to the JSON language:
Dynamic import
I'm loading all languages dynamically in order to minimize startup time.
Given that I'm loading the Monaco bundle like so:
import * as Monaco from '/path/to/monaco.bundle.js';
, before I load the JSON language dynamically the following is true:Monaco.languages === window.monaco.languages
, after I load the JSON language contribution,'monaco-editor/esm/vs/language/json/monaco.contribution'
that equality doesn't hold anymore, so it looks like the language contribution is doing something funny with it.Also after loading the language this way creating a JSON editor from the
Monaco
variable doesn't really work, the text is not highlighted at all, if I instead create a JSON editor from thewindow.monaco
variable it works, but then the theme is revered back to the default one for some reason.This is the content of that contribution file:
And it doesn't look right to me, it references a
monaco
variable without importing it, so perhaps that's part of the problem here.Basically I couldn't get the JSON language to work at all when dynamically importing it.
Static import
If I load the JSON language contribution directly in my bundled Monaco entrypoint instead it works, and
Monaco.languages
remains equal tomonaco.languages
🤷♂️TL;DR: I think
monaco-json
basically doesn't work that well when using ESM.The text was updated successfully, but these errors were encountered: