Unable to resolve path to module 'stream/promises'
Asked Answered
C

3

15

For the following import in a typescript nodejs app

import { pipeline } from "stream/promises";

vscode / eslint is complaining Unable to resolve path to module 'stream/promises'

sample

This started occurring all of a sudden.

node -v v16.13.2
pnpm -v 6.29.1
"@types/node": "^17.0.12"

stream/promises is part of node. I've confirmed that the pipeline function and typescript type exist and work and the overall app still functions.

console.log({ pipeline }); // { pipeline: [Function: pipeline] }

Importing just stream works with no complaints. I've confirmed this error on a Windows 10 and Linux computer. Whats going on and how to resolve it without ignoring it?

Carcinogen answered 5/2, 2022 at 23:33 Comment(4)
Simply typing import { pipeline } I get auto-suggestion to from 'stream'. Probably that's how it should be imported, otherwise it might think 'stream/promises' is a file path?Protoactinium
@Protoactinium Thats for the sync version of pipeline. The async version is found under stream/promisesCarcinogen
Did you solve it? same here..Refresh
@Refresh Nope. Had to eslint ignore.Carcinogen
H
8

Need to make sure your node version is > v15. Note that if you're using nvm, your terminal node version could be different from the version vscode is using. You can see which version you have with nvm unload; node -v. You can consider adding nvm to your rc script files but sometimes it doesn't resolve fast enough and vs code complains.

Hidalgo answered 9/11, 2022 at 0:40 Comment(0)
S
1

make sure you have "@types/node" in your package.json. and make sure its version is > 15, e.g.

"@types/node": "^18.11.0",
Sundberg answered 27/11, 2023 at 14:12 Comment(0)
U
0

For serverless / middyjs

Error: "Runtime.ImportModuleError: Error: Cannot find module 'stream/promises'"

Context:

On debugging it is observed that the error is from @middy/core ( version: 4.6.5 ) which is dependent on node:stream/promises (reference) which requires node version >=15.x

Fix here

Check for serverless.yml > provider > runtime

and update it to a version >= 15.x

provider:
  name: aws
  runtime: nodejs16.x

If you are using custom plugins like esbuild, make sure to update to the same node version

custom:
    esbuild:
      bundle: true
      target: node16
      platform: node

Note: If you are not using stream/promises in your code and still facing the error ( like I did ), check for any recent package updates in the code and see if they internally use stream/promises.

Umberto answered 25/10, 2023 at 6:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.