uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.65k stars 132 forks source link

`Codemirror plugin crashed: TypeError: tags4 is undefined` #401

Closed NashJames closed 1 year ago

NashJames commented 1 year ago

So this error appears in the console on every page load when trying to load a language extension on both firefox and chrome (although chrome defines it as Codemirror plugin crashed: TypeError: tags4 is not iterable).

I've tried using loadLanguage('json') from @uiw/codemirror-extensions-langs and json() from @codemirror/lang-json. No formatting is applied. The code mirror appears to work correctly.

@uiw/react-codemirror v4.13.0
@uiw/codemirror-extensions-langs v4.13.0
parcel v2.4.0
@codemirror/lang-json v6.0.1
Error screenshot ![Screenshot 2022-11-10 at 11 56 10](https://user-images.githubusercontent.com/37304960/201086474-fafa63b3-efba-4155-b65a-f37fb60c05d1.png)

Also, I've written some code to determine language based on file extension like below, but I have to write a huge type for it because loadLanguage() doesn't allow strings unless they match a type. You can't use typeof langNames because it's formatted with ()[]. Adding a type to the repo would be very helpful.

type languages = "apl" | "asciiArmor" | ...

const path = "example/path.tsx"
const split = path.split(".")
const lang =  split[split.length - 1] as languages

...

extensions={[loadLanguage(lang)]}
jaywcjlove commented 1 year ago

Can you provide a reproducible example using codesandbox.io?

@NashJames

NashJames commented 1 year ago

Just spent an hour trying. Hit one error on the sandbox, and another on github codespaces. No idea what caused either.

image

image

jaywcjlove commented 1 year ago

@NashJames I don't have any problems locally but I have problems on codesandbox example

image

I don't know how to solve it, if you solved it please share your answer.

thx!

NashJames commented 1 year ago

For the time being, my plan is to use it without language support. If I ever give it another go and figure out the cause, I’ll come back and let you know.

Up to you if you wish to close this. I can always reopen if I do figure it out.

miguelski commented 1 year ago

also using parcel and i got the error image

image here is the actual error

UPDATE: bump parcel to 2.8 and run rm -rf .parcel-cache node_modules package-lock.json fixed the issue

NashJames commented 1 year ago

Thanks @miguelski. I'm assuming this is the correct fix but we're not in a position to upgrade parcel due to another bug. So I can't test.

I'll consider this fixed and close the issue and make a note in our project readme.

karlhorky commented 1 year ago

What worked for me was manually editing the Yarn lockfile (yarn.lock) to remove any entries which had >1 version numbers that were conflicting (eg. @lezer/common@1.0.2 and @lezer/common@1.0.3) and then re-running yarn install to install the latest version.

Often I use Yarn Resolutions or pnpm Overrides to force the versions of transitive dependencies, which avoids this problem when upgrading dependencies. However, like some others in this thread, I have a dependency on older (pre-v1) versions of @lezer/common and @lezer/lr packages via Parcel 😨 So for these packages, Yarn Resolutions and pnpm Overrides cannot be used, because they will cause incompatibilities with the @mischnic/json-sourcemap dependency from Parcel.

So manual upgrades for now until we can either remove the Parcel dependency or upgrade it (currently it's pinned on an old version from a different dependency).