-
-
Notifications
You must be signed in to change notification settings - Fork 159
fix(next): make computed relative chunk requires resolve in a compiled App Route #8146
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
Merged
+102
−9
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8030ccc
fix(cjs): resolve computed relative requires against the module's own…
963cc75
test(cjs): pin the computed-relative-require join
2645516
fix(codegen): record path->init addresses before the eager init loop
48c1b7a
test(cjs): the presence probe follows the joined specifier
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| A compiled production Next.js App Route no longer dies at startup with `Cannot find module './chunks/2.js'`. | ||
|
|
||
| Next's production webpack runtime loads lazy chunks by a *computed* relative specifier — `.next/server/webpack-runtime.js` calls `require("./chunks/" + g.u(a))`. Perry's CJS `require` shim passed that string straight to the path→module registry, which is keyed by each module's **absolute** source path, so the lookup could never hit. Statically-known relative specifiers are resolved at compile time and never reach that branch; only computed ones do, which is why this only showed up on the real production route. | ||
|
|
||
| The result was that every lazy chunk was unreachable at runtime even though it had been compiled into the image — all 104 modules of the #8034 fixture produced object files, `chunks/2.js` among them, and the host still exited during startup. | ||
|
|
||
| Computed relative specifiers are now joined against the requiring module's own directory before the registry lookup. The `./` prefix is stripped textually rather than left to `std::fs::canonicalize`, which only normalizes paths that exist on disk while registration falls back to the raw string when they do not — relying on it would work from a source tree and silently fail in the deployed case the dylib packaging exists for. | ||
|
|
||
| Refs #8040, #5438. | ||
|
|
||
| A second defect sat behind the first. Even with the correct absolute key, the lookup missed: `perry_module_init` ran every eager module init *before* recording the path→init addresses, so a module performing a runtime path-require during its own init — which is exactly when Next's `webpack-runtime` loads a chunk — queried an init registry that was still empty. The addresses it needed were recorded a few instructions later. | ||
|
|
||
| Recording is pure bookkeeping (no init runs at that point), so it now happens before the eager-init loop. | ||
|
|
||
| Both defects had to be fixed to get past startup; either alone still fails, which is why the first fix alone showed no improvement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Resolve exact
.and..specifiers."."and".."are valid relative specifiers. This branch leaves both as raw registry keys, so a computed form such asrequire("." + "")can still throwMODULE_NOT_FOUND. Join"."tomodule_dir_literaland preserve".."like the existing../branch. Add canaries for both forms.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents