Skip to content

Conversation

@serhalp
Copy link
Member

@serhalp serhalp commented Oct 22, 2025

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.

@github-actions
Copy link

github-actions bot commented Oct 22, 2025

📊 Benchmark results

Comparing with 6a38183

  • Dependency count: 1,029 (no change)
  • Package size: 284 MB (no change)
  • Number of ts-expect-error directives: 379 (no change)

@serhalp serhalp force-pushed the fix/throws-on-exports-condition-module-sync branch 2 times, most recently from 79f9b4a to 5930f6f Compare October 22, 2025 20:26
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))
Copy link
Member Author

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).
@serhalp serhalp force-pushed the fix/throws-on-exports-condition-module-sync branch from 5930f6f to e80c5a6 Compare October 22, 2025 21:23
@serhalp serhalp marked this pull request as ready for review October 22, 2025 22:07
@serhalp serhalp requested a review from a team as a code owner October 22, 2025 22:07
@serhalp serhalp force-pushed the fix/throws-on-exports-condition-module-sync branch from 82c9cd4 to 01dd0d5 Compare October 23, 2025 13:51
Comment on lines +291 to +292
process.allowedNodeEnvironmentFlags.has('--no-experimental-require-module') ||
process.allowedNodeEnvironmentFlags.has('--experimental-require-module'),
Copy link
Member Author

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

@serhalp serhalp merged commit 25fab29 into main Oct 23, 2025
52 of 53 checks passed
@serhalp serhalp deleted the fix/throws-on-exports-condition-module-sync branch October 23, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants