Npm workspace cache issue

Hello,

Me and my team have been trying to get set up NPM workspaces within Netlify and have partially managed to do so. The only issue is that with every new commit, the preview build fails as it is not installing the correct dependencies.

We suspect that it is looking at the cache but not finding our dependencies which are located at the root of the repo and not within the package. As you can see in the build log below, the build command fails because the next package was not installed. **Important: ** clear cache and retry deploying always works. But for obvious reasons we don’t want to have to select this every time.

Our current repo structure:
root:

  • package.json
  • package-lock.json
  • app.website:
    • package.json
    • netlify.toml

The netlify site name is moonpay-landing-page.netlify.app

Full build log:

5:06:27 PM: Build ready to start
5:06:30 PM: build-image version: ac716c5be7f79fe384a0f3759e8ef612cb821a37 (xenial)
5:06:30 PM: build-image tag: v3.13.0
5:06:30 PM: buildbot version: 515e5c33287d8b909c004fcf2e460e8645e8c1c6
5:06:30 PM: Fetching cached dependencies
5:06:33 PM: Finished downloading cache in 2.744713793s
5:06:33 PM: Starting to extract cache
5:06:39 PM: Finished extracting cache in 6.643158425s
5:06:39 PM: Finished fetching cache in 9.424005841s
5:06:39 PM: Starting to prepare the repo for build
5:06:40 PM: Preparing Git Reference pull/416/head
5:06:41 PM: Parsing package.json dependencies
5:06:42 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'app.website/.next' versus '.next' in the Netlify UI
5:06:42 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'app.website/app.website/out_functions' versus 'app.website/out_functions' in the Netlify UI
5:06:43 PM: Starting build script
5:06:43 PM: Installing dependencies
5:06:43 PM: Python version set to 2.7
5:06:43 PM: Started restoring cached node version
5:06:45 PM: Finished restoring cached node version
5:06:45 PM: Attempting node version 'v16' from .nvmrc
5:06:45 PM: v16.15.1 is already installed.
5:06:46 PM: npm WARN config This command does not support workspaces.
5:06:46 PM: Now using node v16.15.1 (npm v8.11.0)
5:06:46 PM: Started restoring cached build plugins
5:06:46 PM: Finished restoring cached build plugins
5:06:46 PM: Attempting ruby version 2.7.1, read from environment
5:06:46 PM: Started restoring cached ruby version
5:06:46 PM: Finished restoring cached ruby version
5:06:48 PM: Using ruby version 2.7.1
5:06:48 PM: Using PHP version 5.6
5:06:48 PM: No npm workspaces detected
5:06:48 PM: Started restoring cached node modules
5:06:48 PM: Finished restoring cached node modules
5:06:48 PM: Started restoring cached go cache
5:06:48 PM: Finished restoring cached go cache
5:06:48 PM: go version go1.14.4 linux/amd64
5:06:48 PM: go version go1.14.4 linux/amd64
5:06:48 PM: Installing missing commands
5:06:48 PM: Verify run directory
5:06:50 PM: ​
5:06:50 PM: ────────────────────────────────────────────────────────────────
5:06:50 PM:   Netlify Build                                                 
5:06:50 PM: ────────────────────────────────────────────────────────────────
5:06:50 PM: ​
5:06:50 PM: ❯ Version
5:06:50 PM:   @netlify/build 27.3.0
5:06:50 PM: ​
5:06:50 PM: ❯ Flags
5:06:50 PM:   baseRelDir: true
5:06:50 PM:   buildId: 62bdbbf245da4300084b6ed2
5:06:50 PM:   deployId: 62bdbbf245da4300084b6ed5
5:06:50 PM: ​
5:06:50 PM: ❯ Current directory
5:06:50 PM:   /opt/build/repo/app.website
5:06:50 PM: ​
5:06:50 PM: ❯ Config file
5:06:50 PM:   /opt/build/repo/app.website/netlify.toml
5:06:50 PM: ​
5:06:50 PM: ❯ Context
5:06:50 PM:   deploy-preview
5:06:50 PM: ​
5:06:50 PM: ❯ Installing plugins
5:06:50 PM:    - @netlify/plugin-nextjs@4.9.3
5:07:00 PM: ​
5:07:00 PM: ❯ Loading plugins
5:07:00 PM:    - @netlify/plugin-nextjs@4.9.3 from netlify.toml
5:07:01 PM: ​
5:07:01 PM: ────────────────────────────────────────────────────────────────
5:07:01 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
5:07:01 PM: ────────────────────────────────────────────────────────────────
5:07:01 PM: ​
5:07:01 PM: Next.js cache restored.
5:07:01 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
5:07:01 PM: ​
5:07:01 PM: (@netlify/plugin-nextjs onPreBuild completed in 317ms)
5:07:01 PM: ​
5:07:01 PM: ────────────────────────────────────────────────────────────────
5:07:01 PM:   2. Build command from Netlify app                             
5:07:01 PM: ────────────────────────────────────────────────────────────────
5:07:01 PM: ​
5:07:01 PM: $ npm run build
5:07:02 PM: > @moonpay/website@0.1.0 build
5:07:02 PM: > next build && rm .next/trace
5:07:02 PM: sh: 1: next: not found
5:07:02 PM: npm ERR! Lifecycle script `build` failed with error:
5:07:02 PM: npm ERR! Error: command failed
5:07:02 PM: npm ERR!   in workspace: @moonpay/website@0.1.0
5:07:02 PM: npm ERR!   at location: /opt/build/repo/app.website
5:07:02 PM: ​
5:07:02 PM: ────────────────────────────────────────────────────────────────
5:07:02 PM:   "build.command" failed                                        
5:07:02 PM: ────────────────────────────────────────────────────────────────
5:07:02 PM: ​
5:07:02 PM:   Error message
5:07:02 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
5:07:02 PM: ​
5:07:02 PM:   Error location
5:07:02 PM:   In Build command from Netlify app:
5:07:02 PM:   npm run build
5:07:02 PM: ​
5:07:02 PM:   Resolved config
5:07:02 PM:   build:
5:07:02 PM:     base: /opt/build/repo/app.website
5:07:02 PM:     command: npm run build
5:07:02 PM:     commandOrigin: ui
5:07:02 PM:     environment:
- Omitted for obvious reasons -
5:07:02 PM:     publish: /opt/build/repo/app.website/.next
5:07:02 PM:     publishOrigin: config
5:07:02 PM:   functionsDirectory: /opt/build/repo/app.website/app.website/out_functions
5:07:02 PM:   headers:
5:07:02 PM:     - for: /*      values:        Strict-Transport-Security: max-age=63072000; includeSubDomains; preload        X-Frame-Options: DENY        X-XSS-Protection: 1; mode=block  headersOrigin: config  plugins:    - inputs: {}      origin: config      package: '@netlify/plugin-nextjs'Caching artifacts
5:07:02 PM: Started saving node modules
5:07:02 PM: Finished saving node modules
5:07:02 PM: Started saving build plugins
5:07:02 PM: Finished saving build plugins
5:07:02 PM: Started saving pip cache
5:07:02 PM: Finished saving pip cache
5:07:02 PM: Started saving emacs cask dependencies
5:07:02 PM: Finished saving emacs cask dependencies
5:07:02 PM: Started saving maven dependencies
5:07:02 PM: Finished saving maven dependencies
5:07:02 PM: Started saving boot dependencies
5:07:02 PM: Finished saving boot dependencies
5:07:02 PM: Started saving rust rustup cache
5:07:02 PM: Finished saving rust rustup cache
5:07:02 PM: Started saving go dependencies
5:07:02 PM: Finished saving go dependencies
5:07:02 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:07:02 PM: Creating deploy upload records
5:07:02 PM: Failing build: Failed to build site
5:07:02 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:07:03 PM: Finished processing build request in 32.725598788s

package.json in root


  "workspaces": [
  "private": true,
    "app.*/"
  ]

Netlify.toml file in app.website

[build]
  publish = ".next"

[functions]
  directory = "app.website/out_functions"

[[plugins]]
  package = "@netlify/plugin-nextjs"

[[headers]]
  for = "/*"
  [headers.values]
    Strict-Transport-Security = "max-age=63072000; includeSubDomains; preload"
    X-Frame-Options = "DENY"
    X-XSS-Protection = "1; mode=block"

Build settings
Screenshot 2022-06-30 at 17.26.28

Hey there, @Michiel_Van_Eetvelde :wave:

My apologies for the slow response! Are you still encountering issues with this? I found a thread with a customer who encountered the same error.

If you’re still having this issue, could you try to set an environment variable with the name NPM_VERSION and value as 8.4.0 (or lower)?