Npm-run-all not found during build despite being in package.json dependencies

I had successful deploys for a while until I tried to integrate with faunadb and implement serverless functions with netlify-lambda. I can build and run functions just fine in dev, but cannot figure out how to get it to work in production.

There were many other issues to work through, but at this moment I seem to be stuck on a simple issue of the npm-run-all dependency not being installed when I deploy. It is in my package.json dev dependencies. The start:appdev command looks the way it does because I am using next.js, and the only way to avoid CORS issues is to run a wrapper server that has proxying middleware (see ‘Using with Next.js’ on netlify-lambda). I’m not sure whether the lambdas will have CORS issues in production, but I can’t deploy to test it.

"scripts": {
    "dev": "npm-run-all --parallel start:appdev start:server",
    "start": "npm-run-all --parallel start:appprod start:server",
    "build": "npm-run-all --parallel build:app build:server",
    "build:app": "next build",
    "build:server": "netlify-lambda build functions",
    "start:appdev": "cross-env PORT=3000 node server.js",
    "start:appprod": "next start",
    "start:server": "netlify-lambda serve functions"
  },

Here’s the deploy output. I’ve tried clearing the cache and I’ve tried to make sure my packagelock.json is in sync by deleting and running npm install.

10:25:49 AM: Build ready to start
10:25:51 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
10:25:51 AM: build-image tag: v3.4.1
10:25:51 AM: buildbot version: c6376102eedf4be6c6e5d685c7141e2eb612d47d
10:25:51 AM: Building without cache
10:25:51 AM: Starting to prepare the repo for build
10:25:51 AM: No cached dependencies found. Cloning fresh repo
10:25:51 AM: git clone https://github.com/ercgrat/creator.urbanbasic.de
10:25:52 AM: Preparing Git Reference refs/heads/master
10:25:53 AM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'out_functions' versus '' in the Netlify UI
10:25:53 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build' versus 'npm run build && npx next export' in the Netlify UI
10:25:53 AM: Starting build script
10:25:53 AM: Installing dependencies
10:25:53 AM: Python version set to 2.7
10:25:54 AM: v12.18.0 is already installed.
10:25:55 AM: Now using node v12.18.0 (npm v6.14.4)
10:25:55 AM: Started restoring cached build plugins
10:25:55 AM: Finished restoring cached build plugins
10:25:55 AM: Attempting ruby version 2.7.1, read from environment
10:25:57 AM: Using ruby version 2.7.1
10:25:57 AM: Using PHP version 5.6
10:25:57 AM: 5.2 is already installed.
10:25:57 AM: Using Swift version 5.2
10:25:57 AM: Started restoring cached node modules
10:25:57 AM: Finished restoring cached node modules
10:25:57 AM: Installing NPM modules using NPM version 6.14.4
10:26:10 AM: > @ampproject/toolbox-optimizer@2.6.0 postinstall /opt/build/repo/node_modules/@ampproject/toolbox-optimizer
10:26:10 AM: > node lib/warmup.js
10:26:10 AM: AMP OPTIMIZER Downloaded latest AMP runtime data.
10:26:11 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/webpack/node_modules/fsevents):
10:26:11 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:26:11 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
10:26:11 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:26:11 AM: added 693 packages from 286 contributors and audited 1020 packages in 12.977s
10:26:11 AM: 35 packages are looking for funding
10:26:11 AM:   run `npm fund` for details
10:26:11 AM: found 4 low severity vulnerabilities
10:26:11 AM:   run `npm audit fix` to fix them, or `npm audit` for details
10:26:12 AM: NPM modules installed
10:26:12 AM: Started restoring cached go cache
10:26:12 AM: Finished restoring cached go cache
10:26:12 AM: go version go1.14.4 linux/amd64
10:26:12 AM: go version go1.14.4 linux/amd64
10:26:12 AM: Installing missing commands
10:26:12 AM: Verify run directory
10:26:13 AM: ​
10:26:13 AM: ┌─────────────────────────────┐
10:26:13 AM: │        Netlify Build        │
10:26:13 AM: └─────────────────────────────┘
10:26:13 AM: ​
10:26:13 AM: ❯ Version
10:26:13 AM:   @netlify/build 4.8.1
10:26:13 AM: ​
10:26:13 AM: ❯ Flags
10:26:13 AM:   deployId: 5f84676d55a733bd2f3baade
10:26:13 AM:   mode: buildbot
10:26:13 AM: ​
10:26:13 AM: ❯ Current directory
10:26:13 AM:   /opt/build/repo
10:26:13 AM: ​
10:26:13 AM: ❯ Config file
10:26:13 AM:   /opt/build/repo/netlify.toml
10:26:13 AM: ​
10:26:13 AM: ❯ Context
10:26:13 AM:   production
10:26:14 AM: ​
10:26:14 AM: ┌────────────────────────────────────┐
10:26:14 AM: │ 1. build.command from netlify.toml │
10:26:14 AM: └────────────────────────────────────┘
10:26:14 AM: ​
10:26:14 AM: $ npm run build
10:26:14 AM: > learn-starter@0.1.0 build /opt/build/repo
10:26:14 AM: > npm-run-all --parallel build:app build:server
10:26:14 AM: sh: 1: npm-run-all: not found
10:26:14 AM: npm ERR! code ELIFECYCLE
10:26:14 AM: npm ERR! syscall spawn
10:26:14 AM: npm ERR! file sh
10:26:14 AM: npm ERR! errno ENOENT
10:26:14 AM: npm ERR! learn-starter@0.1.0 build: `npm-run-all --parallel build:app build:server`
10:26:14 AM: npm ERR! spawn ENOENT
10:26:14 AM: npm ERR!
10:26:14 AM: npm ERR! Failed at the learn-starter@0.1.0 build script.
10:26:14 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
10:26:14 AM: npm ERR! A complete log of this run can be found in:
10:26:14 AM: npm ERR!     /opt/buildhome/.npm/_logs/2020-10-12T14_26_14_538Z-debug.log
10:26:14 AM: ​
10:26:14 AM: ┌─────────────────────────────┐
10:26:14 AM: │   "build.command" failed    │
10:26:14 AM: └─────────────────────────────┘
10:26:14 AM: ​
10:26:14 AM:   Error message
10:26:14 AM:   Command failed with exit code 1: npm run build
10:26:14 AM: ​
10:26:14 AM:   Error location
10:26:14 AM:   In build.command from netlify.toml:
10:26:14 AM:   npm run build
10:26:14 AM: ​
10:26:14 AM:   Resolved config
10:26:14 AM:   build:
10:26:14 AM:     command: npm run build
10:26:14 AM:     commandOrigin: config
10:26:14 AM:     environment:
10:26:14 AM:       - FAUNADB_ADMIN_SECRET
10:26:14 AM:       - FAUNADB_CLIENT_SECRET
10:26:14 AM:       - FAUNADB_SERVER_SECRET
10:26:14 AM:       - FAUNA_DB_SECRET
10:26:14 AM:       - NEXT_PUBLIC_PAYPAL_ENV
10:26:14 AM:       - NODE_ENV
10:26:14 AM:     functions: /opt/build/repo/out_functions
10:26:14 AM:     publish: /opt/build/repo/out
10:26:14 AM: Caching artifacts
10:26:14 AM: Started saving node modules
10:26:14 AM: Finished saving node modules
10:26:14 AM: Started saving build plugins
10:26:14 AM: Finished saving build plugins
10:26:14 AM: Started saving pip cache
10:26:14 AM: Finished saving pip cache
10:26:14 AM: Started saving emacs cask dependencies
10:26:14 AM: Finished saving emacs cask dependencies
10:26:14 AM: Started saving maven dependencies
10:26:14 AM: Finished saving maven dependencies
10:26:14 AM: Started saving boot dependencies
10:26:14 AM: Finished saving boot dependencies
10:26:14 AM: Started saving go dependencies
10:26:14 AM: Finished saving go dependencies
10:26:17 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:26:17 AM: Failing build: Failed to build site
10:26:17 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
10:26:17 AM: Finished processing build request in 26.570924409s

I’ve been able to work around this particular issue by prefacing all of my commands with npx, which will find and install each node module before executing it. I still think it’s an issue that my dev dependencies are not being installed via npm install prior to the build command.

I’m still unable to deploy however because of this issue with zip-it-and-ship-it:

The tutorials available for the faunadb addon assume the legacy style of executing lambda functions. This was my mistake!

I switched my whole configuration over to using netlify cli (netlify build + netlify dev). Much much easier. Create the functions using netlify cli as well.

I can’t explain the above issues, but everything surrounding the legacy netlify-lambda serve was a headache.

Glad to hear you got things working as you desired in the end!

I think that behavior is more about how npm works than Netlify, @ercgrat :slight_smile: When$NODE_ENV is set to production, devDependencies are not installed.

You’d need to make it non-dev Dependencies for us to install them (or set NODE_ENV to development).

Seems obvious… I didn’t realize there was a difference in the behavior of npm install based on NODE_ENV. Is it a bug then that this deploys correctly with the switch to cli? I moved all of my incorrectly devdependencies already but that was after I managed to fix this.

CLI == you build locally, we have little control over how your environment there is set up.

Otherwise, when we build, you get our defaults unless you configure yours :slight_smile:

So - I don’t think it’s a bug