codemirror / lang-example

Example/template repository for building a language package
MIT License
69 stars 43 forks source link

Error: Unrecognized extension value in extension set ([object Object]) #3

Closed Azorlogh closed 3 years ago

Azorlogh commented 3 years ago

Hi, I followed the README in this repo and follow this tutorial to bundle codemirror with rollup.

However, when I replace the lang-javascript package with my own, I get the following error:

Uncaught Error: Unrecognized extension value in extension set ([object Object]). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.

It happens without changing lang-example at all, and all the tests pass.

I made sure to use compatible versions of the @codemirror/x packages (tried originally with 0.18.x, and updated to 0.19.x), but the issue persists.

marijnh commented 3 years ago

Did you check whether multiple instances of \@codemirror/state are installed? Even when your package.json is entirely reasonable, npm will sometimes upgrade an existing install in a way that needlessly duplicates packages.

Azorlogh commented 3 years ago

I figured out the issue: This was caused by the presence of node_modules in the lang-example subdirectory after building. If I delete node_modules, everything works. The solution was to add a config option to nodeResolve when building my app with rollup:

nodeResolve({
    dedupe: ["@codemirror/state"]
})

I think this could be a good info to add to the "Bundling with Rollup" article.

marijnh commented 3 years ago

I think this could be a good info to add to the "Bundling with Rollup" article.

Well, that kind of masks the problem of the duplicated install existing in the first place (running with another bundler or with raw ES modules, you'd still hit the error). The good news is that this seems to happen a lot less with non-0.x versions (because after 1.0, npm will consider all 1.x releases compatible, and thus be less inclined to duplicate them—at least, that was the experience with ProseMirror).

Azorlogh commented 3 years ago

I see, hopefully it'll get better with 1.0 then :+1:

joshmarinacci commented 3 years ago

I also just ran into the bug using this template repo and by following the instructions in the Rollup and Writing a Language Package examples. This was with a clean checkout, so I suspect anyone will run into this with the current setup.

marijnh commented 3 years ago

Running npm install in a clean checkout of this repository gave you duplicated packages? Which npm version is that happening with?