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?

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?
    – tromgy
    Commented Feb 5, 2022 at 23:41
  • 1
    @tromgy Thats for the sync version of pipeline. The async version is found under stream/promises
    – SILENT
    Commented Feb 6, 2022 at 0:25
  • Did you solve it? same here..
    – Danpe
    Commented Oct 5, 2022 at 12:18
  • 1
    @Danpe Nope. Had to eslint ignore.
    – SILENT
    Commented Oct 5, 2022 at 23:12

3 Answers 3

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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.