Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS7016 compilation error - prosemirror-state/dist/index.js implicitly has an any type #1456

Closed
adamretter opened this issue Apr 10, 2024 · 7 comments

Comments

@adamretter
Copy link

adamretter commented Apr 10, 2024

We are having some trouble using ProseMirror in our TypeScript project - evolvedbinary/prosemirror-jdita.

Our CI (https://app.circleci.com/pipelines/github/evolvedbinary/prosemirror-jdita/238/workflows/2e59929e-174d-447f-b4a5-ee373ebd8fd0/jobs/916) shows these errors when compiling:

../node_modules/prosemirror-commands/dist/index.d.ts:2:25 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/home/circleci/project/node_modules/prosemirror-state/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-state' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`

2 import { Command } from 'prosemirror-state';
                          ~~~~~~~~~~~~~~~~~~~

../node_modules/prosemirror-history/dist/index.d.ts:1:59 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/home/circleci/project/node_modules/prosemirror-state/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-state' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`

1 import { Transaction, Plugin, Command, EditorState } from 'prosemirror-state';
                                                            ~~~~~~~~~~~~~~~~~~~

../node_modules/prosemirror-keymap/dist/index.d.ts:1:33 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/home/circleci/project/node_modules/prosemirror-state/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-state' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`

1 import { Command, Plugin } from 'prosemirror-state';
                                  ~~~~~~~~~~~~~~~~~~~

../node_modules/prosemirror-menu/dist/index.d.ts:2:50 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/home/circleci/project/node_modules/prosemirror-state/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-state' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`

2 import { EditorState, Transaction, Plugin } from 'prosemirror-state';
                                                   ~~~~~~~~~~~~~~~~~~~

../node_modules/prosemirror-view/dist/index.d.ts:1:61 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/home/circleci/project/node_modules/prosemirror-state/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-state' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`

1 import { EditorState, Transaction, Selection, Plugin } from 'prosemirror-state';
                                                              ~~~~~~~~~~~~~~~~~~~

../node_modules/prosemirror-view/dist/index.d.ts:3:25 - error TS7016: Could not find a declaration file for module 'prosemirror-transform'. '/home/circleci/project/node_modules/prosemirror-transform/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-transform' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-transform';`

3 import { Mapping } from 'prosemirror-transform';
                          ~~~~~~~~~~~~~~~~~~~~~~~


Found 6 errors in 5 files.

Our package.json imports the following dependencies:

"prosemirror-commands": "^1.5.2",
"prosemirror-history": "^1.3.2",
"prosemirror-keymap": "^1.2.2",
"prosemirror-menu": "^1.2.4",
"prosemirror-model": "^1.19.4",
"prosemirror-schema-list": "^1.3.0",
"prosemirror-state": "^1.4.3",
"prosemirror-view": "^1.32.7",
"prosemirror-transform": "^1.8.0"

I feel like it is unlikely that this is expected behaviour with ProseMirror and TypeScript, and more likely that we are doing something silly (apologies if that is the case).

I did ask in your Forum (7 days ago), also I also asked in the TypeScript Discord channel (6 days ago) but got no response from either. Sorry to also ask here, but it does seem like a technical issue, and it is really blocking us from moving forward.

Kindest regards, and thank you. Adam.

@marijnh
Copy link
Member

marijnh commented Apr 11, 2024

Have you tried upgrading TypeScript to something more recent? I see you're using 4.6, which is two years old.

@adamretter
Copy link
Author

@marijnh Thanks for your response. Following your suggestion I just tried again with the newer TypeScript versions:

  • 4.9.5 (January 2023)
  • 5.0.4 (April 2023)
  • 5.1.6 (July 2023)
  • 5.2.2 (August 2023)
  • 5.3.3 (December 2023)
  • 5.4.5 (April 2024)

Unfortunately it makes no difference, and they all fail with the same error as we are seeing with TypeScript 4.6.3 currently.

@adamretter
Copy link
Author

I experimented with adding some compiler options in our project's tsconfig.json. The issue only goes away if I set either of the following two options:

Obviously neither of these options are particularly desirable in a TypeScript project as they loosen the type checking performed by the compiler.

I note that whilst the prosemirror-commands, prosemirror-history, prosemirror-keymap, prosemirror-menu, and prosemirror-view modules all have an dist/index.d.ts file, there is NO such index.d.ts file in the prosemirror-state or prosemirror-transform modules. Does that mean that perhaps the TypeScript compiler is correct, and that these declarations are missing from some ProseMirror modules?

@marijnh
Copy link
Member

marijnh commented Apr 11, 2024

That seems unlikely, if you really have prosemirror-state version 1.4.3.

> npm i prosemirror-state
added 5 packages in 296ms
> npm ls
tmp@ /home/marijn/tmp
└── prosemirror-state@1.4.3
> ls node_modules/prosemirror-state/dist
index.cjs  index.d.cts	index.d.ts  index.js

@adamretter
Copy link
Author

Thanks for that insight @marijnh, we are using Yarn instead of npm, but I was able to re-produce your results using the equivalent commands; that is reassuring!

This has given me something to go on though... I note that if I run the following:

nvm use 20
cd /tmp
git clone https://github.com/evolvedbinary/prosemirror-jdita.git test1
cd test1
git checkout test/unit-test-prosemirror
yarn install

Then after that there are these two folders:

  1. /tmp/test1/node_modules/prosemirror-state/dist:
tree node_modules/prosemirror-state/dist
node_modules/prosemirror-state/dist
├── index.es.js
├── index.es.js.map
├── index.js
└── index.js.map
  1. /tmp/test1/prosemirror-jdita/node_modules/prosemirror-state/dist:
$ tree prosemirror-jdita/node_modules/prosemirror-state/dist
prosemirror-jdita/node_modules/prosemirror-state/dist
├── index.cjs
├── index.d.cts
├── index.d.ts
└── index.js

NOTE: Only one of those two folders contains the index.d.ts file!

If I then run yarn build we again see messages like:

../node_modules/prosemirror-commands/dist/index.d.ts:2:25 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/private/tmp/test1/node_modules/prosemirror-state/dist/index.js' implicitly has an 'any' type.
  If the 'prosemirror-state' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`

2 import { Command } from 'prosemirror-state';
                          ~~~~~~~~~~~~~~~~~~~

The fact that there is a ../ at the start of the error message, makes me think it is incorrectly looking in /tmp/test1/node_modules and not /tmp/test1/prosemirror-jdita/node_modules. This could perhaps explain why it can't find the prosemirror-state/dist/index.d.ts file I guess?!?

So at this point I am wondering if there is something screwed up about our build settings in package.json and/or tsconfig.json. Let me talk to the team, investigate, and come back to this after that...

@marijnh
Copy link
Member

marijnh commented Apr 12, 2024

Yeah, that's yarn. I recommend not to use yarn, it creates weird trees with needlessly duplicated dependencies, which breaks this library (and loads way more code than you want to load). Recent npm versions are much better at this.

@adamretter
Copy link
Author

@marijnh Thank you very much for your time and help. We finally diagnosed that our yarn.lock file had two entries for prosemirror-state one for version 1.3.3 and one for version 1.4.3. After deleting the yarn.lock file and re-generating it with yarn, our errors went away. Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants