Skip to content

fix(netlify): support lambda event requests and cjs cache exports#8439

Draft
azinod wants to merge 1 commit intoweb-infra-dev:mainfrom
azinod:fix/netlify-runtime-and-request-adapter
Draft

fix(netlify): support lambda event requests and cjs cache exports#8439
azinod wants to merge 1 commit intoweb-infra-dev:mainfrom
azinod:fix/netlify-runtime-and-request-adapter

Conversation

@azinod
Copy link

@azinod azinod commented Mar 11, 2026

Summary

This PR fixes two follow-up Netlify runtime regressions we hit while validating the Netlify deploy path after the bootstrap filename fix from #8379:

1.

The first problem was that server-side CommonJS output could end up doing require('@modern-js/runtime/cache'), but the ./cache subpath only exported an ESM target. In a real Netlify function this caused startup to fail with:

Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/@modern-js/runtime/dist/esm/cache/index.mjs from /var/task/server/lib/cache/setup.js not supported.

To fix that, this PR adds a CommonJS-compatible node.require export for @modern-js/runtime/cache and points the default export at the CJS build.

2.

The second problem was in the Netlify request adapter. The generated Netlify handler was forwarding the Lambda-style Netlify event directly into server.handle(...), but Hono expects a real Fetch Request with a url. In production this caused:

TypeError: Cannot read properties of undefined (reading 'indexOf')
    at Hono.getPath (/var/task/node_modules/hono/dist/cjs/utils/url.js:103:21)
    at #dispatch (/var/task/node_modules/hono/dist/cjs/hono-base.js:298:23)
    at Hono.fetch (/var/task/node_modules/hono/dist/cjs/hono-base.js:347:26)
    at /var/task/node_modules/@modern-js/prod-server/dist/cjs/netlify.js:48:39
    at Runtime.handler (/var/task/netlify-handler.cjs:73:24)

To fix that, this PR teaches @modern-js/prod-server/netlify to:

  • detect whether it already received a web Request
  • otherwise convert the Netlify Lambda event into a Fetch Request
  • pass that Request to server.handle(...)
  • convert the returned Response back into a Netlify-compatible function response

Together these changes make the generated Netlify function artifact work in the downstream app we used for verification, both locally and in actual Netlify branch deploys.

Related Links

Checklist

  • I have added changeset via pnpm run change.
  • I have updated the documentation.
  • I have added tests to cover my changes.

Validation

  • pnpm --filter @modern-js/runtime build
  • pnpm --filter @modern-js/prod-server build
  • packed patched local Modern.js packages and consumed them from a downstream app
  • verified require.resolve('@modern-js/runtime/cache') resolves to dist/cjs/cache/index.js in the generated Netlify function bundle
  • verified the generated @modern-js/prod-server/dist/cjs/netlify.js contains the Netlify event -> Request adapter logic in the downstream app's .netlify/functions output
  • validated the generated artifact path through Netlify branch deploys for poc and develop

@netlify
Copy link

netlify bot commented Mar 11, 2026

Deploy Preview for modernjs-byted ready!

Name Link
🔨 Latest commit 0e60e12
🔍 Latest deploy log https://app.netlify.com/projects/modernjs-byted/deploys/69b1b6be32392700082a6964
😎 Deploy Preview https://deploy-preview-8439--modernjs-byted.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

⚠️ No Changeset found

Latest commit: 0e60e12

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant