monaco-react icon indicating copy to clipboard operation
monaco-react copied to clipboard

Intellisense stopped working when I tried to use node_modules version instead of CDN

Open nanachi-code opened this issue 2 years ago • 7 comments

Everything works fine until I tried to setup the loader to use the node_modules version.

import * as monaco from "monaco-editor"
// both didnt work
loader.config({ monaco })
loader.config({
  paths: {
    vs: "node_modules/monaco-editor/min/vs"
  }
})

self.MonacoEnvironment = {
  getWorker(_, label) {
    console.log(label) //? this returns editorWorkerService

    if (label === "typescript" || label === "javascript") {
      return new tsWorker()
    }
    return new editorWorker()
  }
}

// ...
// no intellisense
 <MonacoEditor
          language="javascript" // here I specified to use js only
          path="script.js"
/>

I'm using monaco-editor 0.41.0, @monaco-editor/react 4.5.2, vite 4.4.4. This is on a tauri app if that's relevant.

nanachi-code avatar Aug 27 '23 13:08 nanachi-code

do you see any errors/warnings in the console?

suren-atoyan avatar Aug 28 '23 03:08 suren-atoyan

nope. I suspect there might be something going on with the worker that made it not be able to load because when I used the cdn ver, it did log javascript and typescript to the console.

nanachi-code avatar Aug 28 '23 10:08 nanachi-code

I also tried to move the whole monaco-editor folder to public and config the loader

loader.config({
  paths: {
    vs: "/monaco-editor/min/vs"
  }
})

but the result was the same. The language worker did not work.

nanachi-code avatar Aug 28 '23 15:08 nanachi-code

somehow when I downgraded to v0.38.0 (same version with the cdn) this works.

I also tried to move the whole monaco-editor folder to public and config the loader

loader.config({
  paths: {
    vs: "/monaco-editor/min/vs"
  }
})

but the result was the same. The language worker did not work.

nanachi-code avatar Aug 28 '23 16:08 nanachi-code

Also experiencing the same issue. Downgrading monaco-editor to 0.40.0 restores intellisense

DominicH247 avatar Aug 29 '23 12:08 DominicH247

My experience is that the editor doesn't recognize "json" as the first language that is requested (loading only the base worker, and not jsonMode). A weird workaround I found was to

  1. Create an editor setting it to a language other than "json" (in my case "mermaid")
  2. And then creating the one with the "json" language and it loads jsonMode and the worker as expected

Update: this was resolved in monaco-editor @ 0.42 See: https://github.com/microsoft/monaco-editor/issues/4159 (Probably can resolve this issue here since it's not related to monaco-react)

elisherer avatar Sep 10 '23 09:09 elisherer

Update: this was resolved in monaco-editor @ 0.42 See: [microsoft/monaco-editor#4159]

Thanks for the pointer. Upgrading monaco-editor to latest (0.43.0) resurrected intellisense for me.

ldstein avatar Sep 12 '23 01:09 ldstein

This issue has been marked as stale due to inactivity. It will be closed in 7 days unless further activity occurs.

github-actions[bot] avatar Mar 26 '25 00:03 github-actions[bot]

Closing due to inactivity. Feel free to reopen if needed.

github-actions[bot] avatar Apr 02 '25 00:04 github-actions[bot]