Below is a minimal, copy-&-paste friendly “lab” that you can run in any directory to see the famous
Error: Cannot find module 'node:stream'
on Node v14.16, and then confirm exactly which third-party package introduced the unsupported import.
- Set your Node version
(NVM example – skip if you already have 14.16)
nvm install 14.16
nvm use 14.16
node -v # → v14.16.0
- Create a fresh project
mkdir node-stream-demo && cd node-stream-demo
npm init -y
- Install a package that does use the new
“node:”-prefixed built-ins (e.g. got@12)
npm i got@12 # got v12+ requires Node ≥16 and
# imports `node:stream` internally
- Add a tiny index.mjs that just imports got
printf "import got from 'got';\nconsole.log('ping');\n" > index.mjs
- Run the file
node index.mjs
You should immediately see something very close to:
internal/modules/cjs/loader.js:888
throw err;
^
Error: Cannot find module 'node:stream'
Require stack:
- …/node_modules/got/dist/source/core/index.js
- …/node_modules/got/dist/source/index.js
- …/index.mjs
Boom — we’ve reproduced the “Node 14 + node:stream” crash.
- Pinpointing the culprit
got is obviously in the stack trace, but in bigger projects you can let
npm ls or pnpm why do the detective work:
npm ls node:stream
# No output – because `node:stream` isn’t a real package
npm ls got
Sample trimmed output:
node-stream-demo@1.0.0 …/node-stream-demo
└── got@12.0.0
So got@12.0.0 is the first dependency that directly imports the built-in
as import {…} from 'node:stream'.
(Other modern packages that exhibit the same issue on Node 14 are
node-fetch@3, undici@5, openai@4, nanoid@4, etc.)
- Fix / Work-arounds
• Upgrade Node to ≥16 (the node: prefix ships in Node 16 LTS).
That’s the cleanest route.
• …or stick to an older major of the offending lib, e.g.:
npm i got@11 # last line that supports Node 14
• …or use tools like esm-node-prefix-to-path in a build step
(not recommended in the long run).
Summary
The error happens because Node ≤14 doesn’t understand the “URL-style”
built-in specifier prefix (node:stream, node:fs, …).
Any package compiled for Node 16+ (our example: got@12) will crash as soon
as that import line is evaluated. Upgrading Node or downgrading the package
eliminates the issue.