Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/nextjs/src/config/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ export function getNextjsVersion(): string | undefined {
return undefined;
}

// Anchored at this package so `next` (a peer dependency) still resolves when the process cwd is not
// the Next.js project root, e.g. custom servers or monorepos started from the repo root.
let sdkRequire: NodeJS.Require;
/*! rollup-include-cjs-only */
sdkRequire = createRequire(__filename);
/*! rollup-include-cjs-only-end */
/*! rollup-include-esm-only */
sdkRequire = createRequire(import.meta.url);
/*! rollup-include-esm-only-end */

function resolveNextjsPackageJson(): string | undefined {
// Anchored at this package so `next` (a peer dependency) still resolves when the process cwd is not
// the Next.js project root, e.g. custom servers or monorepos started from the repo root.
// Not created at module scope: the server entry imports this module, and webpack-built Cloudflare
// workers have an empty `__filename`, so `createRequire` would throw on import.
let sdkRequire: NodeJS.Require;
/*! rollup-include-cjs-only */
sdkRequire = createRequire(__filename);
/*! rollup-include-cjs-only-end */
/*! rollup-include-esm-only */
sdkRequire = createRequire(import.meta.url);
/*! rollup-include-esm-only-end */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing regression test for import crash

Low Severity

This fix PR does not add a unit, integration, or E2E test for the regression, which the testing convention requires. A unit test can assert that importing the helper does not invoke createRequire, without a Cloudflare worker app. Flagged because it is called out in the review rules.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 5176777. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires a new specific e2e test app that runs Next 15 + OpenNext without any edge routes, our current apps cannot house such a test. I didn't want to do that for a v10.

Will leave this for reviewers to decide.


for (const nodeRequire of [createRequire(`${process.cwd()}/`), sdkRequire]) {
try {
return nodeRequire.resolve('next/package.json');
Expand Down
Loading