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

Strange netlify deployment issues and bugs with monorepo #2411

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

Strange netlify deployment issues and bugs with monorepo #2411

jbool24 opened this issue May 2, 2024 · 3 comments

Comments

@jbool24
Copy link

jbool24 commented May 2, 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: [email protected]
Builder: -
User Config: sourcemap, typescript, experimental, modules, nitro, routeRules, site, sitemap
Runtime Modules: @nuxt/[email protected], @nuxt/[email protected], @nuxtjs/[email protected], [email protected]
Build Modules: -

Reproduction

Cannot repoduce in stackblitz due to wasm env but a repo is available here https://github.com/jbool24/nuxt-netlify-deploy

Describe the bug

There are issues when deploying to Netlfiy with a mono repo.

Intention:

To deploy from a mono repo that is structured with N number of Nuxt3 projects. All projects are top level and there would be a ./layers dir top level as well to author shared local layers between projects. Currently this is achieved with pnpm workspaces. Any project may iterate over time and "may" have split handling using routeRules. At the current state of this setup only static files are generated for deployment with the intention of adding CMS based dynamic routes over time to the Nuxt app. As its is setup right now this issue has two parts that seem to surface which seem like a bug:

Current state:

When using a mono repository setup with Netlify presets (should be zero config) as output for nitro some strange things happen:

  1. There is a phantom dir that gets created under the app directory when using netlify-cli tools to preview the build process. For example within the reproduction link provided, "app_dir" which is one full nuxt project will see {{MONO_REPO_ROOT}}/app_dir/app_dir/.netlify/functions-internal created within the existing {{MONO_REPO_ROOT}}/app_dir however nothing is output here. This is also incorrect as it should instead be inside {{MONO_REPO_ROOT}}/app_dir/.netlify folder that already exists in the nuxt project's root. Even though the end result of the build process outputs a server directory (and assets) in the correct {{MONO_REPO_ROOT}}/app_dir/.netlify/functions-internal/server directory.
  2. Nitro/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 and the (seo module)[https://nuxt.com/modules/seo] the redirects for sitemap routes instruct netlify with the following:
# File: ./dist/_redirects  
/sitemap.xml /sitemap_index.xml	302
/sitemap_index.xml	/.netlify/builders/server 200 <-- (/.netlify/builders/server doesn't exist and causes 404)
/__nuxt_error	/.netlify/functions/server 200 <-- (/.netlify/builders/server doesn't exist and causes 404)
/* /.netlify/functions/server 200

Additional context

Relates to nuxt/nuxt#27026

As Netlify docs instruct for monorepos, a project level netlify.toml should specify the base for use during deployment. In theory, Netlify may be able to auto detect a monorepo but there would be a requirement to also build deps from a top level "layers" shared between nuxt projects so we specify a base dir

[build]
base = "app_dir/"
command = "pnpm build"
publish = "dist/"

The following are relative logs from the Nuxt build process triggered by Netlfiy cli using ntl serve to debug/preview a deployment. This is run from the mono-repo root.

✔ 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

Tail end of netlify build process and dev server logs (Notice the redirect to non-existing file path. No functions deployed at current state of the Nuxt project with static only routes except sitemap.xmls

Σ 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

Logs

No response

@Rigo-m
Copy link
Contributor

Rigo-m commented May 10, 2024

Hi, been using pnpm monorepos with nuxt3 layers for a long time. No issues there.
Didn't use netlify.toml.
This is my config though
image
I think you can try removing the base directory and mimic what I've done in the screenshot.
Here's my folder structure:

- packages/
   - design-system
   - global
package.json
pnpm-workspace.yml   

@jbool24
Copy link
Author

jbool24 commented May 10, 2024

@Rigo-m Do each of your packages contain their own package.json or are all dependencies shared at the top level in node_modules?

I still think there was a small issue in presets/netlify.ts which I think @serhalp has started working on this as v2 preset

@Rigo-m
Copy link
Contributor

Rigo-m commented May 10, 2024

I both have shared dependencies and specific package.json.
Nuxt should be in the package.json file of your package (app_dir).

To my understanding, there are zero problems with the "old" netlify preset.
We have at least half a dozen websites being served by nuxt3+pnpm monorepo+netlify combo. I am 99.99% sure yours is a configuration issue.
If you want to dwell deeper on this issuse hit me on twitter.

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

3 participants