Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netlify nitro deployment adds _redirects file with non-existing server functions directory #27026

Open
jbool24 opened this issue May 1, 2024 · 2 comments

Comments

@jbool24
Copy link

jbool24 commented May 1, 2024

Environment


  • Operating System: Linux
  • Node Version: v18.18.0 // <--- using v20 in prod but this doesn't change the outcomes described
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: pnpm@8.15.6
  • Builder: -
  • User Config: sourcemap, typescript, experimental, modules, nitro, routeRules, site, sitemap
  • Runtime Modules: @nuxt/ui@2.15.2, @nuxt/content@2.12.1, @nuxtjs/sitemap@5.1.4, nuxt-og-image@3.0.0-rc.52
  • Build Modules: -

Reproduction

This will not reproduce in a stackblitz env due to wasm but there is a repo with the project to clone and test.
https://github.com/jbool24/nuxt-netlify-deploy

Describe the bug

When using a mono repository setup and Netlify presets for nitro some strange things happen:

  1. There is a phantom dir that gets created under the app directory when using netlify-cli to preview the build process. For example within the reproduction link provided, "app_dir" which is a full nuxt directory will see {{MONO_REPO_ROOT}}/app_dir/app_dir/.netlify/functions-internal created within the existing {{MONO_REPO_ROOT}}/app_dir instead of inside the correct {{MONO_REPO_ROOT}}/app_dir/.netlify folder that already exists in the project. Even though the end result of the build outputs a server directory in the correct {{MONO_REPO_ROOT}}/app_dir/.netlify/functions-internal/server directory
  2. Nuxt outputs a _redirect into the dist directory for netlify use in deployment. When a simple deployment prerenders some pages with route rules and also using the sitemap seo module the redirects for sitemap instruct netlify with the following:
# ./dist/_redirects  <-- (/.netlify/builders/server doesn't exist and causes 404)
/sitemap.xml /sitemap_index.xml	302
/sitemap_index.xml	/.netlify/builders/server 200
/__nuxt_error	/.netlify/functions/server 200
/* /.netlify/functions/server 200

maybe I'm dumb and .netlfiy/builders/server is a virtual route but if netlify only sees static files at the moment there is no serverless functions deployed so this is failing with 404. Attempted to change NITRO_PRESET from "netlify" to "netlify-builder" and this makes no difference in the outcomes mentioned in this issue. Looking at https://github.dev/unjs/nitro/blob/main/src/presets/netlify.ts it seems this may default to make certain assumptions here that don't reflect the instance configuration. (Again this may be my mistake which I will gladly be corrected to get things working 😜)

Additional context

The netlify command is run from the mono_repo root ntl serve to test the build and review config of what netlify will serve on the platform. Currently the demo has only static files to deploy but would in theory add dynamic things in the future (this may change the output with server routes to use "swr" settings to produce dynamic blog pages for example.

# This lives in the app of a single deployment -- in theory there would me multiple projects with a top level "layers" shared between nuxt projects in the mono repo
[build]
base = "app_dir/"
command = "pnpm build"
publish = "dist/"

Logs

✔ Server built in 13560ms                                                                                                                                                                                                       11:55:22 AM   
ℹ Initializing prerenderer                                                                                                                                                                                                nitro 11:55:22 AM   
ℹ Prerendering 3 routes                                                                                                                                                                                                   nitro 11:55:29 AM   
  ├─ /api/_content/cache.1714578893919.json (192ms)                                                                                                                                                                        nitro 11:55:29 AM  
  ├─ /api/_content/query/cdzJXZdsvf.1714578893919.json (6ms)                                                                                                                                                                                                                                                                                                                                            nitro 11:55:29 AM  
  ├─ / (440ms)                                                                                                                                                                                                             nitro 11:55:29 AM  
  ├─ /_payload.json (2ms)                                                                                                                                                                                                  nitro 11:55:29 AM  
ℹ Prerendered 6 routes in 13.385 seconds                                                                                                                                                                                  nitro 11:55:35 AM   
[nitro] Nitro now uses `isr` option to configure ISR behavior on Netlify. Backwards-compatible support for `static` and `swr` support with Builder Functions will be removed in the future versions. Set `future.nativeSWR: true` nitro config
 disable this warning.                                                                                                                                                                                                                        
✔ Generated public dist                                                                                                                                                                                                   nitro 11:55:36 AM   
ℹ Building Nuxt Nitro server (preset: netlify-builder)                                                                                                                                                                    nitro 11:55:36 AM   
✔ Nuxt Nitro server built                                                                                                                                                                                                 nitro 11:55:46 AM   
  ├─ .netlify/functions-internal/server/chunks/_/empty.mjs (126 B) (124 B gzip)                                                                                                                                                               
  ├─ .netlify/functions-internal/server/chunks/_/error-500.mjs (5.05 kB) (2.09 kB gzip)                                                                                                                                                       
  ├─ .netlify/functions-internal/server/chunks/_/node.mjs (142 B) (132 B gzip)

# ... etc
Σ Total size: 44.1 MB (17.4 MB gzip)

(build.command completed in 58s)

Functions bundling                                            
────────────────────────────────────────────────────────────────


(Functions bundling completed in 1ms)

Save deploy artifacts                                         
────────────────────────────────────────────────────────────────


(Save deploy artifacts completed in 1ms)

Netlify Build Complete                                        
────────────────────────────────────────────────────────────────

(Netlify Build completed in 58s)

◈ Static server listening to 3999

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Redirecting /sitemap.xml to /sitemap_index.xml
◈ Rewrote URL to /.netlify/builders/server # <-- navigating to /sitemap which gets 404
@danielroe
Copy link
Member

Would you see if you can reproduce this in pure Nitro (reproduction sandbox), and if so, raise there? 🙏

@jbool24
Copy link
Author

jbool24 commented May 2, 2024

@danielroe I'm not sure its possible to reproduce as pure nitro, only because the current configuration state for the project which I have causing this does not use any ssr yet (at least to my understanding -- there is no server dir). Unless one of the modules is bootstraping behind the scenes. The seo module portion is where I think I'm hung up and may be the issue. I'm just noticing that it won't output a static sitemap and infers that a netlify function will resolve it (which is what the produced _redirects is telling netlify).

I can and will open this on the nitro side though and link back to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants