nitro icon indicating copy to clipboard operation
nitro copied to clipboard

When ssr: false, baseURL is not set to _nuxt folder after build. Can not find /_nuxt/ files

Open issue-up[bot] opened this issue 2 years ago • 6 comments

   Forwarded from downstream issue:

  • https://github.com/nuxt/nuxt/issues/21780 by @Nura-21

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)

issue-up[bot] avatar Jun 26 '23 08:06 issue-up[bot]

Think I'm running into the same issue:

Screenshot 2023-06-26 at 18 47 21

SleepiestAdam avatar Jun 26 '23 17:06 SleepiestAdam

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.

image

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.

image

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.

jsunico avatar Jul 03 '23 05:07 jsunico

@danielroe Is this something you plan to work on?

pi0 avatar Jul 03 '23 09:07 pi0

@danielroe @pi0 Hi! Are there any updates?

trdln avatar Jul 07 '23 10:07 trdln

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.

image

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.

image

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.

Unfortunately workaround doesn't work in my deployment flow with Cleavr.

LynxTR avatar Feb 27 '24 14:02 LynxTR

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

ryanweston avatar Apr 22 '24 13:04 ryanweston