sindresorhus/file-type

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

dpopp07 opened this issue · 5 comments

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

From version file-type version 16 to 17, it changed from a CommonJS to ES-Module. To isolate the issue, you may want to try the latest 16.x first. Can you create a simple repo reproducing the issue @dpopp07?

From version file-type version 16 to 17, it changed from a CommonJS to ES-Module. To isolate the issue, you may want to try the latest 16.x first. Can you create a simple repo reproducing the issue @dpopp07?

@Borewit thanks for the reply. Everything is working fine with 16.5.4, I ran into these issues when trying to use v17. I should be able to create a simple repo to reproduce, good idea. I'll try to do that soon

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".

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,