FurqanSoftware / codemirror-languageserver

Language Server integration for CodeMirror 6
BSD 3-Clause "New" or "Revised" License
183 stars 24 forks source link

"Events" error #26

Closed Mirza-Glitch closed 1 year ago

Mirza-Glitch commented 1 year ago

I'm having solid js project which use vite to start the front-end. I'm having a codemirror based code editor in my project, and I'm using jsonrpc-ws-proxy to start the lsp server (I'm using tsserver). Everything was working fine but after using codmirror-languageserver I'm getting an error which looks like this:

events_1.EventEmitter is not a constructor
at new RequestManager3 (http://localhost:5173/node_modules/.vite/deps/codemirror-languageserver.js?v=1f2a4f85:166:33)
at new LanguageServerClient (http://localhost:5173/node_modules/.vite/deps/codemirror-languageserver.js?v=1f2a4f85:8253:27)
at Editor (http://localhost:5173/src/components/editor/Editor.jsx?t=1693083118230:26:13)
at http://localhost:5173/@solid-refresh:25:42
at untrack (http://localhost:5173/node_modules/.vite/deps/chunk-QUWHAVPQ.js?v=1f2a4f85:493:12)
at HMRComp.createMemo.name [as fn] (http://localhost:5173/@solid-refresh:25:28)
at runComputation (http://localhost:5173/node_modules/.vite/deps/chunk-QUWHAVPQ.js?v=1f2a4f85:796:22)
at updateComputation (http://localhost:5173/node_modules/.vite/deps/chunk-QUWHAVPQ.js?v=1f2a4f85:775:3)
at createMemo (http://localhost:5173/node_modules/.vite/deps/chunk-QUWHAVPQ.js?v=1f2a4f85:270:5)
at [solid-refresh]Editor (http://localhost:5173/@solid-refresh:22:20)

Not just that, i also had another warning from vite which said:

Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

I followed the link they provided, it ironically mentions "it's advised to report the issue to the respective library".

I've tried various ways but nothing works. I've checked server, it works fine so looks problem from frontend side. I think it's somewhere problem with dependencies of codemirror-languageserver package, how do I resolve this ?

Here is how I used the codemirror-languageserver package at Frontend:

const serverUri = new WebSocket("ws://localhost:3000/typescript");

var ls = new languageServer({
    serverUri,
    rootUri: "file:///",
    documentUri: `file:///index.ts`,
    languageId: "typescript",
  });
const extensions = [
    basicSetup,
    javascript(),
    ls,
    autocompletion({
      override: [myCompletions],
    }),
  ];
const state = EditorState.create({
    doc: " ",
    extensions,
  });
Mirza-Glitch commented 1 year ago

The issue was related to openrpc client library which is used by codemirror-languageserver. I found the solution at this thread, I just needed to install events package by running npm i events. However I got into another error which might be related to codemirror, the error looks like this:

Config merge conflict for field override
at combineConfig (http://localhost:5173/node_modules/.vite/deps/chunk-MKFMOIK6.js?v=fda1d2b4:2566:15)
at _Facet.combine (http://localhost:5173/node_modules/.vite/deps/chunk-33JKMBHJ.js?v=fda1d2b4:299:12)
at _Configuration.resolve (http://localhost:5173/node_modules/.vite/deps/chunk-MKFMOIK6.js?v=fda1d2b4:1797:29)
at _EditorState.create (http://localhost:5173/node_modules/.vite/deps/chunk-MKFMOIK6.js?v=fda1d2b4:2418:39)
jbromberg commented 8 months ago

The issue was related to openrpc client library which is used by codemirror-languageserver. I found the solution at this thread, I just needed to install events package by running npm i events. However I got into another error which might be related to codemirror, the error looks like this:

Config merge conflict for field override
at combineConfig (http://localhost:5173/node_modules/.vite/deps/chunk-MKFMOIK6.js?v=fda1d2b4:2566:15)
at _Facet.combine (http://localhost:5173/node_modules/.vite/deps/chunk-33JKMBHJ.js?v=fda1d2b4:299:12)
at _Configuration.resolve (http://localhost:5173/node_modules/.vite/deps/chunk-MKFMOIK6.js?v=fda1d2b4:1797:29)
at _EditorState.create (http://localhost:5173/node_modules/.vite/deps/chunk-MKFMOIK6.js?v=fda1d2b4:2418:39)

hey i also have this error. did you ever fix this?

Edit: fixed it by removing my old autocomplete extension that had override set.