Missing dependency during build

Hello,

I’m trying to deploy my site but failing. Here is the relevant section of the deploy log:

3:01:33 PM: $ npm run build
3:01:34 PM: > diabetes-food-database@7.0.0 build /opt/build/repo
3:01:34 PM: > vite build
3:01:34 PM: sh: 1: vite: not found
3:01:34 PM: npm ERR! code ELIFECYCLE
3:01:34 PM: npm ERR! syscall spawn
3:01:34 PM: npm ERR! file sh
3:01:34 PM: npm ERR! errno ENOENT
3:01:34 PM: npm ERR! diabetes-food-database@7.0.0 build: `vite build`
3:01:34 PM: npm ERR! spawn ENOENT
3:01:34 PM: npm ERR!
3:01:34 PM: npm ERR! Failed at the diabetes-food-database@7.0.0 build script.

It looks like Vite isn’t found. I thought it would get installed automatically during build because it’s part of my development dependencies. See my package.json here.

I tried to “Clear cache and retry deploy” but received the same error.

The site is dfdb.netlify.app (there’s an older version deployed right now).

The public repo is GitHub - travishorn/diabetes-food-database: Food information for people with diabetes.

The full build log is pasted below.

3:00:51 PM: Build ready to start
3:00:53 PM: build-image version: 6ac9cdbcc295289dbaea7d39b2f1a3ac25ad3380 (xenial)
3:00:53 PM: build-image tag: release-v3.14.0
3:00:53 PM: buildbot version: 667117c26805e29113bede4ca1afe54070a4e3b1
3:00:53 PM: Fetching cached dependencies
3:00:53 PM: Starting to download cache of 258.6MB
3:00:56 PM: Finished downloading cache in 2.281036142s
3:00:56 PM: Starting to extract cache
3:01:03 PM: Finished extracting cache in 7.135274707s
3:01:03 PM: Finished fetching cache in 9.51516344s
3:01:03 PM: Starting to prepare the repo for build
3:01:03 PM: Preparing Git Reference refs/heads/master
3:01:03 PM: Parsing package.json dependencies
3:01:04 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'dist' versus '/' in the Netlify UI
3:01:04 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'src/functions' versus '' in the Netlify UI
3:01:04 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build' versus '' in the Netlify UI
3:01:05 PM: Starting build script
3:01:05 PM: Installing dependencies
3:01:05 PM: Python version set to 2.7
3:01:05 PM: Started restoring cached node version
3:01:07 PM: Finished restoring cached node version
3:01:08 PM: v8.17.0 is already installed.
3:01:08 PM: Now using node v8.17.0 (npm v6.13.4)
3:01:08 PM: Started restoring cached build plugins
3:01:08 PM: Finished restoring cached build plugins
3:01:08 PM: Attempting ruby version 2.3.6, read from environment
3:01:09 PM: Started restoring cached ruby version
3:01:09 PM: Finished restoring cached ruby version
3:01:10 PM: Using ruby version 2.3.6
3:01:11 PM: Successfully installed bundler-2.3.18
3:01:11 PM: 1 gem installed
3:01:11 PM: Using PHP version 5.6
3:01:11 PM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
3:01:12 PM: No npm workspaces detected
3:01:12 PM: Started restoring cached node modules
3:01:12 PM: Finished restoring cached node modules
3:01:12 PM: Installing NPM modules using NPM version 6.13.4
3:01:28 PM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
3:01:28 PM: > yorkie@2.0.0 uninstall /opt/build/repo/node_modules/yorkie
3:01:28 PM: > node bin/uninstall.js
3:01:28 PM: husky
3:01:28 PM: uninstalling Git hooks
3:01:28 PM: done
3:01:30 PM: > vue-demi@0.13.5 postinstall /opt/build/repo/node_modules/pinia/node_modules/vue-demi
3:01:30 PM: > node ./scripts/postinstall.js
3:01:31 PM: added 22 packages from 45 contributors, removed 987 packages, updated 6 packages and audited 122 packages in 17.872s
3:01:31 PM: 3 packages are looking for funding
3:01:31 PM:   run `npm fund` for details
3:01:31 PM: found 0 vulnerabilities
3:01:31 PM: NPM modules installed
3:01:31 PM: Started restoring cached go cache
3:01:32 PM: Finished restoring cached go cache
3:01:32 PM: Installing Go version 1.10
3:01:32 PM: unset GOOS;
3:01:32 PM: unset GOARCH;
3:01:32 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64';
3:01:32 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64/bin:${PATH}";
3:01:32 PM: go version >&2;
3:01:32 PM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.10.linux.amd64.env';
3:01:32 PM: go version go1.10 linux/amd64
3:01:32 PM: Installing missing commands
3:01:32 PM: Verify run directory
3:01:33 PM: ​
3:01:33 PM: ────────────────────────────────────────────────────────────────
3:01:33 PM:   Netlify Build                                                 
3:01:33 PM: ────────────────────────────────────────────────────────────────
3:01:33 PM: ​
3:01:33 PM: ❯ Version
3:01:33 PM:   @netlify/build 27.4.2
3:01:33 PM: ​
3:01:33 PM: ❯ Flags
3:01:33 PM:   baseRelDir: false
3:01:33 PM:   buildId: 62d9b0738ddb4800083074f4
3:01:33 PM:   deployId: 62d9b0738ddb4800083074f6
3:01:33 PM: ​
3:01:33 PM: ❯ Current directory
3:01:33 PM:   /opt/build/repo
3:01:33 PM: ​
3:01:33 PM: ❯ Config file
3:01:33 PM:   /opt/build/repo/netlify.toml
3:01:33 PM: ​
3:01:33 PM: ❯ Context
3:01:33 PM:   production
3:01:33 PM: ​
3:01:33 PM: ────────────────────────────────────────────────────────────────
3:01:33 PM:   1. build.command from netlify.toml                            
3:01:33 PM: ────────────────────────────────────────────────────────────────
3:01:33 PM: ​
3:01:33 PM: $ npm run build
3:01:34 PM: > diabetes-food-database@7.0.0 build /opt/build/repo
3:01:34 PM: > vite build
3:01:34 PM: sh: 1: vite: not found
3:01:34 PM: npm ERR! code ELIFECYCLE
3:01:34 PM: npm ERR! syscall spawn
3:01:34 PM: npm ERR! file sh
3:01:34 PM: npm ERR! errno ENOENT
3:01:34 PM: npm ERR! diabetes-food-database@7.0.0 build: `vite build`
3:01:34 PM: npm ERR! spawn ENOENT
3:01:34 PM: npm ERR!
3:01:34 PM: npm ERR! Failed at the diabetes-food-database@7.0.0 build script.
3:01:34 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
3:01:34 PM: npm ERR! A complete log of this run can be found in:
3:01:34 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-07-21T20_01_34_171Z-debug.log
3:01:34 PM: ​
3:01:34 PM: ────────────────────────────────────────────────────────────────
3:01:34 PM:   "build.command" failed                                        
3:01:34 PM: ────────────────────────────────────────────────────────────────
3:01:34 PM: ​
3:01:34 PM:   Error message
3:01:34 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
3:01:34 PM: ​
3:01:34 PM:   Error location
3:01:34 PM:   In build.command from netlify.toml:
3:01:34 PM:   npm run build
3:01:34 PM: ​
3:01:34 PM:   Resolved config
3:01:34 PM:   build:
3:01:34 PM:     command: npm run build
3:01:34 PM:     commandOrigin: config
3:01:34 PM:     environment:
3:01:34 PM:       - NODE_ENV
3:01:34 PM:     publish: /opt/build/repo/dist
3:01:34 PM:     publishOrigin: config
3:01:34 PM:   functionsDirectory: /opt/build/repo/src/functions
3:01:34 PM: Caching artifacts
3:01:34 PM: Started saving node modules
3:01:34 PM: Finished saving node modules
3:01:34 PM: Started saving build plugins
3:01:34 PM: Finished saving build plugins
3:01:34 PM: Started saving pip cache
3:01:34 PM: Finished saving pip cache
3:01:34 PM: Started saving emacs cask dependencies
3:01:34 PM: Finished saving emacs cask dependencies
3:01:34 PM: Started saving maven dependencies
3:01:34 PM: Finished saving maven dependencies
3:01:34 PM: Started saving boot dependencies
3:01:34 PM: Finished saving boot dependencies
3:01:34 PM: Started saving rust rustup cache
3:01:34 PM: Finished saving rust rustup cache
3:01:34 PM: Started saving go dependencies
3:01:35 PM: Finished saving go dependencies
3:01:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:01:35 PM: Creating deploy upload records
3:01:35 PM: Failing build: Failed to build site
3:01:35 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
3:01:36 PM: Finished processing build request in 42.540082263s

I’m sure I’ve misconfigured something or I skipped a step when preparing to deploy. Any help is appreciated. Thanks!

I just looked at the deploy log more closely. This line in the log indicates the problem:

3:01:11 PM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed

I’m now looking for the best solution. I do want NODE_ENV to be production since this is a production build. Perhaps there’s a way to have Netlify install development dependencies regardless of environment.

In the meantime, I will simply move my devDependencies into dependencies.

That’s nothing to do with Netlify - you set Node Environment to production which explicitly tells npm to not install devDependencies. That’s how npm works.

By default, Node Environment on Netlify is set to development just to install devDependencies.