node-fetch: Cannot find module 'node:http` on AWS Lambda v14
Upgrade from version 3.0 to 3.1 produces a Runtime.ImportModuleError: Error: Cannot find module 'node:http on AWS Lambda runtime.
Screenshots
Your Environment
| software | version |
|---|---|
| node-fetch | 3.1 |
| node | 14 |
Additional context
Looks like node: prefix for imports added as part of https://github.com/node-fetch/node-fetch/pull/1346 causes this issue. I am happy to submit MR with a revert of this one, but I need to understand the reason why this prefix has been added here on the first place. Can you suport me on this one please @dnalborczyk ?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 17
- Comments: 34 (10 by maintainers)
100s of 1000s of programmers will have to Google this error, come here, and apply the patch. That seems to be a colossal waste of time.
And esbuild is often used implicitly. I.e. if you use CDK with the NodeJsFunction, it calls esbuild. People might not even know that happens.
the latest
node.jsversion onawsis now14.18.1and therefore supports thenode:prefix forcommonjs.Although true, “node:http” is breaking builds everywhere, and not supported until you have very modern node versions. I suggest wait till the next node LTS.
you can find out running
process.versions.node. anyhow, as of today: v12.22.4 and v14.17.4I very simple solution for ESBuild have been suggested here: https://github.com/evanw/esbuild/issues/1760#issuecomment-964900401
Is there anyone having problems with this outside of ESBuild?
A change like this should have been made in a major version bump IMO
@martin-dimitrov13 thats done
https://github.com/node-fetch/node-fetch/pull/1368
https://nodejs.org/dist/latest-v17.x/docs/api/esm.html#node-imports
We are targeting node v12.20 and above. and
node:prefix got supported in 12.20 for esm syntax, but not for require syntax until v14.18