resolve dev-mode Nuxt entry via Vite @fs absolute path#191
Open
marconett wants to merge 1 commit into
Open
Conversation
…oss-origin preview 404)
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates how the module computes the Nuxt app entry URL in dev mode so it reliably resolves under Vite (including when the entry lives under node_modules) and uses the correct async entry file.
Changes:
- Switches dev entry URL generation to Vite’s
@fs/<absolute-path>mechanism. - Accounts for
baseURLandbuildAssetsDirwhen constructing the entry URL. - Selects
entry.async.jsin dev (matching Nuxt Vite behavior), withbuildIdcache-busting.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
145
to
+151
| const appDir = nuxt.options.appDir.replace(/\/+$/, '') | ||
| const rootDir = nuxt.options.rootDir.replace(/\/+$/, '') | ||
| const relativeAppDir = appDir.startsWith(rootDir) | ||
| ? appDir.slice(rootDir.length + 1) | ||
| : appDir | ||
| const baseURL = (nuxt.options.app.baseURL || '/').replace(/\/+$/, '') | ||
| const assetsDir = (nuxt.options.app.buildAssetsDir || '/_nuxt/').replace(/^\/+|\/+$/g, '') | ||
| const useAsyncEntry = nuxt.options.experimental?.asyncEntry || nuxt.options.dev | ||
| const entryName = useAsyncEntry ? 'entry.async' : 'entry' | ||
| const buildId = nuxt.options.appConfig?.nuxt?.buildId | ||
| resolvedEntryPath = `/_nuxt/${relativeAppDir}/entry.js` + (buildId ? `?v=${buildId}` : '') | ||
| resolvedEntryPath = `${baseURL}/${assetsDir}/@fs${appDir}/${entryName}.js` + (buildId ? `?v=${buildId}` : '') |
Comment on lines
+148
to
+149
| const useAsyncEntry = nuxt.options.experimental?.asyncEntry || nuxt.options.dev | ||
| const entryName = useAsyncEntry ? 'entry.async' : 'entry' |
Comment on lines
+146
to
+147
| const baseURL = (nuxt.options.app.baseURL || '/').replace(/\/+$/, '') | ||
| const assetsDir = (nuxt.options.app.buildAssetsDir || '/_nuxt/').replace(/^\/+|\/+$/g, '') |
| const entryName = useAsyncEntry ? 'entry.async' : 'entry' | ||
| const buildId = nuxt.options.appConfig?.nuxt?.buildId | ||
| resolvedEntryPath = `/_nuxt/${relativeAppDir}/entry.js` + (buildId ? `?v=${buildId}` : '') | ||
| resolvedEntryPath = `${baseURL}/${assetsDir}/@fs${appDir}/${entryName}.js` + (buildId ? `?v=${buildId}` : '') |
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.
Problem
In dev mode (
nuxt dev), the app-loader fails to load the Nuxt app entry in cross-origin previews (Nuxt frontend embedded in Drupal Canvas):The Vite dev server actually serves the entry from:
nuxt build/nuxt generateare unaffected (they read the real chunk frombuild:manifest).Root cause
The
if (nuxt.options.dev)branch insrc/module.tssynthesizes a build-style entry URL instead of using the form Vite actually serves. Two things are wrong:Path. It strips
appDirto a path relative torootDir:The entry lives in
node_modules/nuxt/dist/app, which Vite does not serve from a root-relative URL — it serves it via the@fs/<absolute-path>mechanism. For any normal single-project frontend (whereappDirisunder
rootDir), this produces/_nuxt/node_modules/nuxt/dist/app/entry.js, which 404s.This is also why the playground masks the bug: there
appDir(<repo>/node_modules/...) is not underrootDir(<repo>/playground), so thestartsWithbranch is skipped and the leftover absolute path happensto be served by Vite. Real consumer projects don't have that layout.
Filename. Dev uses the async entry.
@nuxt/vite-builderresolvesuseAsyncEntry = experimental.asyncEntry || nuxt.options.dev, so in dev the entry is alwaysentry.async.js, notentry.js.Fix
Build the dev entry URL from the entry's absolute filesystem path using Vite's canonical
@fs/prefix, and use the async entry filename.Result:
/_nuxt/@fs/<project>/node_modules/nuxt/dist/app/entry.async.js, which matches what the dev server serves.Scope / safety
if (nuxt.options.dev)branch. The!nuxt.options.devpath (build:manifest, used by bothnuxt buildandnuxt generate) is untouched.baseURL/buildAssetsDirare now honored for non-default configs.Verification
nuxt dev: the app-loader now emits the@fsURL and it returns 200 (previously the synthesized path; the playground's monorepo layout hid the breakage).nuxt devfrontend): preview now renders; entry request returns 200 instead of 404.nuxt build+node .output/server/index.mjs: unchanged, still renders previews.Acknowledgement
This PR was written with the help of AI, tho I manually verified and tested it within my nuxt (v4.4.6) project.