When ssr: false, baseURL is not set to _nuxt folder after build. Can not find /_nuxt/ files
Forwarded from downstream issue:
|
Environment
- Operating System: Linux
- Node Version: v16.20.0
- Nuxt Version: 3.6.0
- Nitro Version: 2.5.1
- Package Manager: [email protected]
- Builder: vite
- User Config: ssr, app
- Runtime Modules: -
- Build Modules: -
It repeats on 3.5.3 too.
Reproduction
Project: https://stackblitz.com/edit/github-llcwvz-tkssrz Build with nuxt generate: https://github-llcwvz-tkssrz.vercel.app/
Describe the bug
When using nuxt generate with ssr: false, with different baseURL, entry files from /_nuxt/ are lost.
Modifying app.buildAssetsDir didn't help.
Additional context
It may not depend on ssr
Logs
Failed to load resource: the server responded with a status of 404 (Not Found)
entry.bbc96c86.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)
error-404.23f2309d.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)
error-404.10e2858c.js:1
Failed to load resource: the server responded with a status of 404 (Not Found)
error-500.aa16ed4d.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)
error-500.55e9e483.js:1
Failed to load resource: the server responded with a status of 404 (Not Found)
Think I'm running into the same issue:
I'm having similar problem with Cloudflare preset but mine's SSR is set to true. Happy to raise this as a new issue if this is a different scenario.
With nuxt config baseURL set to /base/, the static files are generated under .output/public/_nuxt/. This results to 404 when requesting files under _nuxt using wrangler dev. Setting the buildAssetsDir to _nuxt won't generate files under .output/public/base/_nuxt instead it's still generated under .output/public/nuxt.
Changing buildAssetsDir to an absolute path (/base/_nuxt/) forces the generation of files under .output/base/_nuxt. However, when I launch the app, the baseURL is duplicated and becomes /base/base/_nuxt/*.js. This also results to 404.
Currently the workaround that worked for me is to override the buildAssetsDir=_nuxt runtime config of nitro. This avoids duplication of the baseURL during runtime while also placing static files to the correct folder during build time.
app: {
baseURL: '/base/',
buildAssetsDir: '/base/_nuxt/',
},
nitro: {
runtimeConfig: {
app: {
buildAssetsDir: '_nuxt'
}
}
}
Haven't tested in vercel but hopefully it works for you in the meantime @SleepiestAdam.
@danielroe Is this something you plan to work on?
@danielroe @pi0 Hi! Are there any updates?
I'm having similar problem with Cloudflare preset but mine's
SSRis set to true. Happy to raise this as a new issue if this is a different scenario.With nuxt config
baseURLset to/base/, the static files are generated under.output/public/_nuxt/. This results to 404 when requesting files under_nuxtusing wrangler dev. Setting thebuildAssetsDirto_nuxtwon't generate files under.output/public/base/_nuxtinstead it's still generated under.output/public/nuxt.
Changing
buildAssetsDirto an absolute path (/base/_nuxt/) forces the generation of files under.output/base/_nuxt. However, when I launch the app, thebaseURLis duplicated and becomes/base/base/_nuxt/*.js. This also results to 404.
Currently the workaround that worked for me is to override the
buildAssetsDir=_nuxtruntime config of nitro. This avoids duplication of thebaseURLduring runtime while also placing static files to the correct folder during build time.app: { baseURL: '/base/', buildAssetsDir: '/base/_nuxt/', }, nitro: { runtimeConfig: { app: { buildAssetsDir: '_nuxt' } } }Haven't tested in vercel but hopefully it works for you in the meantime @SleepiestAdam.
Unfortunately workaround doesn't work in my deployment flow with Cleavr.
This is an issue with Vercel deployments also. Public and build assets are prefixed with the baseURL correctly in the DOM but will continue to served from the root, thus returning a 404.
Can provide a reproduction if needed @pi0 @danielroe

