Prevent npm from running on deploy

I added the deploy settings of NODE_ENV production and all of my node modules are within dev dependencies yet npm still runs on deploy. For background, I have a jekyll site and I only need node for local development (I’m running grunt for image minification, css prefixes, and what not).

12:28:26 PM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
12:28:27 PM: No npm workspaces detected
12:28:27 PM: Started restoring cached node modules
12:28:27 PM: Finished restoring cached node modules
12:28:27 PM: Installing NPM modules using NPM version 8.11.0
12:28:27 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
12:28:27 PM: npm WARN config location in the cache, and they are managed by
12:28:27 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
12:28:28 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
12:28:28 PM: npm WARN config location in the cache, and they are managed by
12:28:28 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
12:28:28 PM: npm ERR! code ERESOLVE
12:28:28 PM: npm ERR! ERESOLVE could not resolve
12:28:28 PM: npm ERR!
12:28:28 PM: npm ERR! While resolving: grunt-contrib-watch@0.6.1
12:28:28 PM: Creating deploy upload records
12:28:28 PM: npm ERR! Found: grunt@1.3.0
12:28:28 PM: npm ERR! node_modules/grunt
12:28:28 PM: npm ERR!   dev grunt@"^1.3.0" from the root project
12:28:28 PM: npm ERR!   peer grunt@">=0.4.2" from grunt-autoprefixer@3.0.4
12:28:28 PM: npm ERR!   node_modules/grunt-autoprefixer
12:28:29 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
12:28:28 PM: npm ERR!     dev grunt-autoprefixer@"^3.0.4" from the root project
12:28:28 PM: npm ERR!   6 more (grunt-concurrent, grunt-cwebp, grunt-newer, ...)
12:28:28 PM: npm ERR!
12:28:28 PM: npm ERR! Could not resolve dependency:
12:28:28 PM: npm ERR! peer grunt@"~0.4.0" from grunt-contrib-watch@0.6.1
12:28:28 PM: npm ERR! node_modules/grunt-contrib-watch
12:28:28 PM: npm ERR!   dev grunt-contrib-watch@"^0.6.1" from the root project
12:28:28 PM: npm ERR!
12:28:28 PM: npm ERR! Conflicting peer dependency: grunt@0.4.5
12:28:28 PM: npm ERR! node_modules/grunt
12:28:28 PM: npm ERR!   peer grunt@"~0.4.0" from grunt-contrib-watch@0.6.1
12:28:28 PM: npm ERR!   node_modules/grunt-contrib-watch
12:28:28 PM: npm ERR!     dev grunt-contrib-watch@"^0.6.1" from the root project
12:28:28 PM: npm ERR!
12:28:28 PM: npm ERR! Fix the upstream dependency conflict, or retry
12:28:28 PM: npm ERR! this command with --force, or --legacy-peer-deps
12:28:28 PM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
12:28:28 PM: npm ERR!
12:28:28 PM: npm ERR! See /opt/buildhome/.npm/eresolve-report.txt for a full report.
12:28:28 PM: npm ERR! A complete log of this run can be found in:
12:28:28 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-06-08T19_28_28_214Z-debug-0.log
12:28:28 PM: Error during NPM install
12:28:28 PM: Build was terminated: Build script returned non-zero exit code: 1
12:28:29 PM: Failing build: Failed to build site
12:28:29 PM: Finished processing build request in 2m58.984619646s

I updated my local modules and updated the grunt version to get it to work, but the point still stands: NPM should not run at all since I just need node to run locally. Is there something I can add to the netlify.toml so I don’t run into these issues in the future?

My understanding is that it’s not possible, based on responses in threads like this:

You could remove the package.json from the repository, then NPM won’t install anything.

1 Like

If you want to prevent the npm install.
You can set the env variable NPM_FLAGS to “–version” on your netlify.toml like this:

[build.environment]
   NPM_FLAGS = "--version

I saw this trick on the vite repo, check this out: vite/netlify.toml at main · vitejs/vite · GitHub