npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community. fails with "rimraf: command not found"

What I Wanted to Do

Follow the Fancy Install (Unix) instructions, on macOS.

Expected to get npm (re)installed.

What Happened Instead

The script failed running pack saying “sh: rimraf: command not found” and left with no npm.

Reproduction Steps

$ curl -L | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5450  100  5450    0     0  30145      0 --:--:-- --:--:-- --:--:-- 30277
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
up to date in 0.039s
sh: rimraf: command not found
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! npm@6.4.1 prepare: `node bin/npm-cli.js --no-audit --no-timing prune --prefix=. --no-global && rimraf test/*/*/node_modules && make -j4 doc`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the npm@6.4.1 prepare script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/john/.npm/_logs/2018-11-10T02_23_01_507Z-debug.log
npm ERR! code E404
npm ERR! 404 Not Found: 1.183s@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/john/.npm/_logs/2018-11-10T02_23_03_041Z-debug.log
It failed


The failure is occurring because of the rimraf in the prepare script in the downloaded package.

    { "prepare": "node bin/npm-cli.js --no-audit --no-timing prune --prefix=. --no-global && rimraf test/*/*/node_modules && make -j4 doc" }
  1. I got a successful install if I globally installed rimraf before running the script.

  2. I got successful install by manually downloading the package and changing the prepare run-script to include the path. This seems like a possible fix at source.

    { "prepare": "node bin/npm-cli.js --no-audit --no-timing prune --prefix=. --no-global && node_modules/rimraf/bin.js test/*/*/node_modules && make -j4 doc" }
  1. I was also able to get an install by defining npm_config_ignore_scripts, or by running with sudo which implicitly disabled the scripts.


This is not a blocker for anything I am doing personally. I investigated it because it was reported as an issue against n in Issue #536 and I wanted to confirm n is not implicated.

I found other reports of the same rimraf error mixed in other threads not specifically about this:

Platform Info

I am running macOS Mojave.

$ npm --versions
{ npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.13.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform


I see there is node_modules/.bin in npm/cli on github, but I do not see a node_modules/.bin in the package downloaded by the install script (and hence rimraf not getting found).

$ curl -s | tar -t - | grep 'rimraf'