fix(build): throw error if there is _next folder inside the public folder - #2814
Open
NriotHrreion wants to merge 3 commits into
Open
Conversation
…folder The `_next` folder under the public folder conflicts with the internal `_next` route, which is not expected
Author
|
Oops, it seems that my formatter just replaced all import relative paths with import alias... |
commit: |
Contributor
Performance benchmarksCompared 1 improved · 0 regressed · 5 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #2778
Root cause
In
packages/vinext/src/server/prod-server.ts:1441, the functionresolveAppRouterAssetPath()does not consider the case where the provided pathname that starts with_next/staticis from public folder.vinext/packages/vinext/src/server/prod-server.ts
Lines 1467 to 1470 in 255be4e
But in the upstream next.js source, it is not allowed to put a
_nextfolder inside the public folder, or it will throw an error duringnpm run build.What changed
I created an assert function
assertNoPublicDirAssetConflict(). This function checks the paths. Once it found there is any_nextinside public folder, it will throw an error and interrupt the build.This assert function is executed during
configResolved()(inpackages/vinext/src/index.ts):async configResolved(config) { + const publicDir = config.publicDir === "" ? null : config.publicDir; + const assetsDir = + config.environments.client.build.assetsDir ?? + config.build.assetsDir ?? + resolveAssetsDir(nextConfig.assetPrefix ?? ""); + + assertNoPublicDirAssetConflict({ + root: config.root, + publicDir, + assetsDir, + }); // ...The workaround is quite simple and is aligned with the behavior of upstream next.js.
Testing
pnpm test tests/public-dir-conflict.test.tsNotes
The error message is as following:
I'm not sure if the link should be replaced with vinext's one.
Thanks for reviewing!