-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module 'node:http` on AWS Lambda v14 #1367
Comments
https://nodejs.org/dist/latest-v17.x/docs/api/esm.html#node-imports We are targeting node v12.20 and above. and |
@jimmywarting In this case it looks like it is going to break for all CJS users between versions 12.20 (your target version) and 14.8. In my case looks like AWS runtime is <14.18. |
Same here, locking at 3.0.0 until a fix is deployed. |
@martin-dimitrov13 thats done |
Are you running some job to compile the source to cjs? |
@jimmywarting, the build part is happening on AWS side. I use CDK framework and I send .ts files to AWS. I believe it is compiled using esbuild under the hood (not 100% confidence about this one). |
Hmm, but version 3.x of node-fetch is ESM only so we don't actually support CJS at all. It seems like in this case there is a build step that turns |
Does |
it's to distinguish between userland modules and node.js built-in modules. it serves as a namespace. |
this is an |
@dnalborczyk thank you for explanation. Today I learned about I will leave it for people smarter than me to decide if it is useful in context for this project or not. I just wanted to report because it broke my project and can potentially affect many more. Wait a sec, because the |
very unlikely. I'm fairly certain the build is happening locally on the dev side.
you are very likely down leveling to commonjs, you should check your you can see it in the stacktrace, |
@dnalborczyk you are right. It is part of a deployment and it is compiled locally using esbuild. |
good question, it depends on the point of view. let's say you use a transpiler (e.g. babel or typescript) in your build step, which down levels also node_modules dependencies. if |
With semver a major change is when you have breakage in your public api. Since CJS wasn't supported at all, I don't think that this should be a major bump. E.g. someone could depend on the exact byte size of the package, and then we add a few lines of code and their project is now to big for the Lambda size restriction. Is that a breaking change for node-fetch?
I'm personally not against removing the prefix, but since we have no tests that covers this, and since there is no documentation that it should work, I think that it will probably end up being broken again down the line... |
We have already had requests like the below that ask for we can't just keep jumping and toggle between using it and not using it. somewhere/somehow i think that bundlers that downlevel code into commonjs should also strip away the |
I'm using esbuild to bundle before deploying to lambda where node-fetch is now broken when using 3.1.0 Here is the relevant esbuild issue where they talk about compiling ESM I'll raise an issue there to see if they can check the target environment and if below v14.18 strip the 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 |
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. |
A change like this should have been made in a major version bump IMO |
it kind of did, yet it didn't for some... We released 3.0.0 with a node-engine field set to 12.20 where Line 14 in 30c3cfe
We just didn't account for backend users to transpile it down to commonjs. I guess a solution for now could be to do what is recommended in: #1279 (comment) ...to use lazy or do what was suggested in ESBuild 👇 |
I very simple solution for ESBuild have been suggested here: evanw/esbuild#1760 (comment) Is there anyone having problems with this outside of ESBuild? |
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. |
I am in agreeance that this should of been a major version increase. You just simply do not touch this kind of stuff in minor version bumps. |
good news for those who use esbuild, a PR was merged to strip away |
looks like jest have also added some support for node protocol a while back: jestjs/jest#11331 |
I'm running into this with node v16.9.1 Worked fine with [email protected] but breaks on v3.1 with
|
My solution for now in case it helps anyone; I was already using // babel.config.js
module.exports = (api) => {
const env = api.env();
// ...
if (env === 'test') {
plugins.push([
'babel-plugin-module-resolver', {
alias: {
'^node:(.*)$': '\\1',
},
}]);
}
// ...
} This will replace all imports that match But ideally #1368 will be merged and this won't be needed, or the jest fixes jestjs/jest#11331 added to jest v27.1 will make it's way into the next version of create-react-app, looks close to v5 milestone |
the latest |
That's amazing! Since Lambda updates to this automatically (the only available runtime for Node.js 14 is |
This broke our smoke test on GitHub Actions with their Node 12 runtime. We transpile our code using Webpack. Any suggestions to remedy the situation? At the moment I'm unable to upgrade node-fetch beyond v3.0. Upgrading Node is not an option because this smoke test intentionally runs against Node 12 in order to guarantee it works in legacy environments. Honest question: is the |
Your action is running 12.22, which should support |
the issue is that they use webpack to probably pack everything to a cjs module really the only possible way would be to compile to esm and if you have to ship your application to AWS lamba as a cjs module then you should load it using async import.
We have already had this requirement in fetch-blob where we try to load dropping it now would only break it for somebody else... |
i'm just guessing now but i think that if you update webpack then it can strip away that node prefix for you alternative is that you have some webpack plugin that resolves modules manually |
Upgrade from version
3.0
to3.1
produces aRuntime.ImportModuleError: Error: Cannot find module 'node:http
on AWS Lambda runtime.Screenshots
Your Environment
Additional context
Looks like
node:
prefix for imports added as part of #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 ?The text was updated successfully, but these errors were encountered: