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: Could not find a declaration file for module '../cid.js' #255

Closed
pablomendezroyo opened this issue Jun 14, 2023 · 6 comments
Closed

Comments

@pablomendezroyo
Copy link

The file interface.ts has an import import { CID } from '../cid.js', see https://github.com/multiformats/js-multiformats/blob/9af03687b545a2e558a23aa23dae50b3a9ac6cc5/src/block/interface.ts#LL4C32-L4C32

when compiling with ts-loader throws the error

ERROR in /node_modules/multiformats/src/block/interface.ts
./node_modules/multiformats/src/block/interface.ts 4:20-31
[tsl] ERROR in /node_modules/multiformats/src/block/interface.ts(4,21)
      TS7016: Could not find a declaration file for module '../cid.js'. '/node_modules/multiformats/src/cid.js' implicitly has an 'any' type.

Looks like there is missing a .ts file for it

@pablomendezroyo
Copy link
Author

This is blocking me from bundling my app with webpack with target node. I managed to remove this library but is widely used by other IPFS libraries such as kubo RPC client

@rvagg
Copy link
Member

rvagg commented Sep 5, 2023

@Gozala would you mind having a quick look at this?

@rvagg
Copy link
Member

rvagg commented Sep 5, 2023

@pablomendezroyo would you be able to share a minimal project setup that can replicate this issue?

@BigLep
Copy link

BigLep commented Sep 5, 2023

Side: maybe this is an example of a class of errors that goes away if we convert to typescript per #249 ?

@Gozala
Copy link
Contributor

Gozala commented Sep 6, 2023

@pablomendezroyo given the path /node_modules/multiformats/src/block/interface.ts is in the error , I am guessing that your setup fails to recognize that there are typedefs in dist directory https://unpkg.com/browse/[email protected]/dist/types/src/ which are supposed to be resolved according to export maps here

"./block/interface": {
"types": "./dist/types/src/block/interface.d.ts",
"import": "./src/block/interface.js"

Without knowing TS version, your tsconfig or the imports in your code leading to this, I'm afraid it is impossible to tell what exactly is misconfigured.

As per @rvagg if you could share small reproducible test case we may be able to help you figure out what the issue is.

Side: maybe this is an example of a class of errors that goes away if we convert to typescript per #249 ?

@BigLep this specific error may go away or it may turn into a different error. Rewriting everything in TS does not imply that everyone will use same TS configuration and version which is where most issues I've seen come from. In fact major reason for generating typedefs (which pure ts projects do as well) is to avoid those issues.

As of this specific error, it is likely happening because TS configuration leads compiler to source code of the node dependency instead of typedef that it should.

@achingbrain
Copy link
Member

This module has been refactored to be TypeScript so these sorts of errors should now be a thing of the past.

Please reopen if you're still having trouble here.

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

5 participants