Cannot find module 'node:stream' or its corresponding type declarations

See original GitHub issue

I’ve just updated the file-type dependency in a TS package I maintain from v7 to v17. I made the necessary code updates but I cannot build my code with TS - I get several errors, all coming from file-type or associated packages from within node_modules. Every error is the same: Cannot find module 'node:stream' or its corresponding type declarations. and it occurs in 5 places:

  • node_modules/file-type/core.d.ts:1:42
  • node_modules/file-type/index.d.ts:1:42
  • node_modules/peek-readable/lib/StreamReader.d.ts:2:26
  • node_modules/strtok3/lib/core.d.ts:3:26
  • node_modules/strtok3/lib/ReadStreamTokenizer.d.ts:3:26

Any idea why I might seeing this? I’m not ruling out that it could be an issue in my environment but I’m not seeing any issue in my code, just in the dependencies.

I’ve tried with Node versions 14.17.5, 16.16.0, and 18.6.0. I’ve also tried with TypeScript versions 4.7.4 (latest) and 3.8.3 (what we normally use for compatibility).

I would appreciate any insight here!

Screenshot of all the errors: Screen Shot 2022-07-26 at 3 26 41 PM

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Borewitcommented, Jul 29, 2022

Adding @types/node to Node.js TypeScript project is a common thing, as that kind of enables the types for the Node.js API. @types/node is defined in peek-readable as a development dependency as well. I don’t think there is a good way I can automatically let you inherit @types/node typings via the dependent modules,

1reaction
dpopp07commented, Jul 28, 2022

Okay @Borewit I created a simple project to reproduce.

While I was putting this together, I learned that installing @types/node actually resolves the issue. So there’s a fairly easy workaround. I just want to see if this is supposed to be a necessary sibling dependency in order to use this package with TypeScript. It doesn’t work “out of the box”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Typings Error on Cannot find module 'stream'. #223
I fixed it while trying to create a sample project for you: I had to add "types": ["node"] to tsconfig.app.json instead of tsconfig.base.json....
Read more >
2 Answers - 2 - Stack Overflow
I'm trying to add Sweetalert2 component in Angular to my project. When I put the npm install sweetalert2 in ...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
I'm getting the error because I'm trying to import the freeCodeCamp icon from the react-icons package, which I don't have installed. import { ......
Read more >
Cannot find module 'X' error in Node.js | bobbyhadz
To solve the "Cannot find module" error in Node.js, make sure to install the package from the error message if it's a third-party...
Read more >
error ts2307: cannot find module or its corresponding type ...
About the declaration for your parser you could use the pegjs/typings/generated-parser.d.ts from your node modules as a starting point.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found