-
Couldn't load subscription status.
- Fork 429
fix: set same Node.js options locally as AWS Lambda does in production #7735
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
Conversation
📊 Benchmark resultsComparing with 6a38183
|
79f9b4a to
5930f6f
Compare
| NODE_OPTIONS: ['--no-experimental-require-module', '--no-experimental-detect-module'] | ||
| // Unfortunately Node.js throws if `NODE_OPTIONS` contains any unsupported flags and these flags have been added | ||
| // and removed in various specific versions in each major line. Luckily Node.js has an API just for this! | ||
| .filter((flag) => process.allowedNodeEnvironmentFlags.has(flag)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that, despite these Node.js features being enabled by default on some subset of these Node.js 20 and 22 versions, AWS Lambda disables them explicitly via flags: https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html#w292aac41c19.. This leads to a mismatch between the local dev Netlify Functions environment and the production (AWS Lambda) environment, leading to confusing bugs like this: netlify/react-router-template#10 (comment).
5930f6f to
e80c5a6
Compare
82c9cd4 to
01dd0d5
Compare
| process.allowedNodeEnvironmentFlags.has('--no-experimental-require-module') || | ||
| process.allowedNodeEnvironmentFlags.has('--experimental-require-module'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may seem weird, but it's because some node.js versions support the positive flag and some node.js versions support the negative flag
Summary
Despite these Node.js features being enabled by default on some subset of these Node.js 20 and 22 versions, AWS Lambda always disables them explicitly via flags: https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html#w292aac41c19.
This leads to a mismatch between the local dev Netlify Functions environment and the production (AWS Lambda) environment, leading to confusing bugs like this: netlify/react-router-template#10 (comment).
This PR replicates the production Netlify Functions behaviour in the local execution environment.
Following the repro steps from the React Router 7 bug above, I've confirmed this fixes it ✅.
It would be nice to add test coverage but I failed to write a failing test 😓.Woo, I did it.