resolve dev-mode Nuxt entry via Vite @fs absolute path - #191
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.
|
Hi, is it possible to get this merged? We're currently evaluating the whole Drupal Canvas -> NuxtJS (via Lupus) setup for a long term project and are a bit unsure in regards to long term maintainability and support. |
|
@marconett hey! I'm sry, I completely missed your PR, it got lost between all the auto-created update PRs. I need to configure this better so this won't happen again. :( Are you still facing the problem? Which custom_elements and canvas_extjs modules are you using? |
|
Hi @fago I just updated my setup to the most recent supported versions:
The problem persists. I updated my patch to support windows (as per Copilot comments) and confirmed that my patch still fixes the issue. |
|
Claude Code: reviewed and reproduced this end-to-end (on behalf of @fago, ticket CSR-172). Verdict: the fix is correct and the bug is real. I could reproduce the 404 on ReproductionThe trigger is narrower than "appDir under rootDir" — it is Nuxt 4's default Matrix (fresh consumer project,
Browser check (headless Chromium loading a page with
With Regression suiteMerged the PR into
The Nitpicks (non-blocking)
Thanks @marconett — the analysis in the PR description was accurate and the patch is minimal and well-scoped. |
|
I ran some manual testing to make sure this works well with vite7/nuxt4.4 and nuxt4.5/vite8 setup. Seems the culprit is the is repo-layout anyway! Thank you, a good fix! Merged! |
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.