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

Screenshot 2021-11-09 at 07 32 57

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)

Most upvoted comments

very simple solution for ESBuild have been suggested here

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.js version on aws is now 14.18.1 and therefore supports the node: prefix for commonjs.

we can’t just keep jumping and toggle between using it and not using it.

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.

Does anyone know how to find out what exact version of node the AWS 14.x Lambda’s are running?

you can find out running process.versions.node. anyhow, as of today: v12.22.4 and v14.17.4

I 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

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