You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 15, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 15, 2026. It is now read-only.
Codemirror does not compile with typescript 4.7 when "module": "node16" and "moduleResolution": "node16" in the tsconfig. Error:
some-path/src/code-mirror.tsx(1,40): error TS7016: Could not find a declaration file for module 'codemirror'. '/private/var/tmp/_bazel/198d81e4f6aafdc263b492f2c04a5df7/sandbox/darwin-sandbox/959/execroot/project/node_modules/codemirror/dist/index.cjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/codemirror` if it exists or add a new declaration (.d.ts) file containing `declare module 'codemirror';`
Why
In a few words, TS introduced new ways to publish and consume type definitions and TS files depending on if you code using ESM or Commonjs.
According to this, adding an index.d.cts does the trick. So I copy-pasted the index.d.ts and renamed it. Then I removed types from the package.json and it did not work.
Also
The same issue seems to affect other packages as well:
I expect this will break with a lot of npm packages. Weird decision of the TypeScript team to define that option in such a way that it doesn't work with the way most packages are being published (single declaration file using ES exports). Does anybody know about a non-invasive way around this (that doesn't break with the old resolution setting)?
I had similar troubles with types not recognised on "strict" mode on TS 4.7, similar to here, and in the end we found that types should also go inside exports, as the first entry. Adapting to @codemirror/view, the relevant keys would be:
// package.json{"name": "@codemirror/view","type": "module","exports": {"types": "./dist/index.d.ts",// <-- add this, notice the dot-slash, also the position is important"import": "./dist/index.js","require": "./dist/index.cjs"},"types": "dist/index.d.ts"// <-- still keep, notice no dot in front}
I updated all my open source npm packages that way.
I have an open PR for this in codemirror/state: codemirror/state#3. If it gets traction I'm happy to introduce similar requests across all the other repos as well. I believe this approach is sufficiently non-invasive (as it is backwards / forwards compatible with both Node and TS)
Activity
marijnh commentedon Jul 5, 2022
I expect this will break with a lot of npm packages. Weird decision of the TypeScript team to define that option in such a way that it doesn't work with the way most packages are being published (single declaration file using ES exports). Does anybody know about a non-invasive way around this (that doesn't break with the old resolution setting)?
revelt commentedon Sep 6, 2022
I had similar troubles with types not recognised on "strict" mode on TS 4.7, similar to here, and in the end we found that
typesshould also go insideexports, as the first entry. Adapting to@codemirror/view, the relevant keys would be:I updated all my open source npm packages that way.
jodyheavener commentedon Oct 31, 2022
Here's a bit more context as well: microsoft/TypeScript#49160 (comment)
I'm eager to see this fixed, so I would be happy to take a stab at it.
prichey commentedon Jan 24, 2023
I have an open PR for this in
codemirror/state: codemirror/state#3. If it gets traction I'm happy to introduce similar requests across all the other repos as well. I believe this approach is sufficiently non-invasive (as it is backwards / forwards compatible with both Node and TS)marijnh commentedon Aug 30, 2023
I think this should be fixed since June now.