rimraf: rimraf in package.json error
Hi, I am using rimraf as a ‘npm run clean’ command in package.json on Windows 10 it does delete the node_modules directory but I am getting the following error :-
C:\Users\Aaron\Examples\HapiJS\simple>npm run clean
> simple-vhost-example@1.0.0 clean C:\Users\Aaron\Examples\HapiJS\simple
> rimraf node_modules
The system cannot find the path specified.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "clean"
npm ERR! node v5.7.0
npm ERR! npm v3.6.0
npm ERR! code ELIFECYCLE
npm ERR! simple-vhost-example@1.0.0 clean: `rimraf node_modules`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the simple-vhost-example@1.0.0 clean script 'rimraf node_modules'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the simple-vhost-example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! rimraf node_modules
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs simple-vhost-example
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls simple-vhost-example
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Aaron\Examples\HapiJS\simple\npm-debug.log
with the package.json file :-
{
"name": "simple-vhost-example",
"version": "1.0.0",
"description": "Simple Hapi.js vhost example",
"main": "index.js",
"dependencies": {
"glue": "^3.2.0",
"hapi": "^13.0.0",
"hoek": "^3.0.4"
},
"devDependencies": {
"rimraf": "^2.5.2"
},
"scripts": {
"start": "node index.js",
"clean": "rimraf node_modules",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "AaronNGray",
"license": "MIT"
}
C:\Users\Aaron\Examples\HapiJS\simple>type npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'clean' ]
2 info using npm@3.6.0
3 info using node@v5.7.0
4 verbose run-script [ 'preclean', 'clean', 'postclean' ]
5 info lifecycle simple-vhost-example@1.0.0~preclean: simple-vhost-example@1.0.0
6 silly lifecycle simple-vhost-example@1.0.0~preclean: no script for preclean, continuing
7 info lifecycle simple-vhost-example@1.0.0~clean: simple-vhost-example@1.0.0
8 verbose lifecycle simple-vhost-example@1.0.0~clean: unsafe-perm in lifecycle true
9 verbose lifecycle simple-vhost-example@1.0.0~clean: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\Aaron\Examples\HapiJS\simple\node_modules\.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\GNU\GnuPG\pub;C:\Program Files (x86)\Skype\Phone\;C:\GnuWin32\bin;C:\Program Files\nodejs\;C:\Users\Aaron\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Git\cmd;C:\Utils;C:\Ruby21-x64\bin;C:\Program Files (x86)\Nmap;C:\Users\Aaron\AppData\Roaming\npm;C:\Program Files (x86)\LLVM\bin
10 verbose lifecycle simple-vhost-example@1.0.0~clean: CWD: C:\Users\Aaron\Examples\HapiJS\simple
11 silly lifecycle simple-vhost-example@1.0.0~clean: Args: [ '/d /s /c', 'rimraf node_modules' ]
12 silly lifecycle simple-vhost-example@1.0.0~clean: Returned: code: 1 signal: null
13 info lifecycle simple-vhost-example@1.0.0~clean: Failed to exec clean script
14 verbose stack Error: simple-vhost-example@1.0.0 clean: `rimraf node_modules`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:232:16)
14 verbose stack at emitTwo (events.js:100:13)
14 verbose stack at EventEmitter.emit (events.js:185:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
14 verbose stack at emitTwo (events.js:100:13)
14 verbose stack at ChildProcess.emit (events.js:185:7)
14 verbose stack at maybeClose (internal/child_process.js:827:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
15 verbose pkgid simple-vhost-example@1.0.0
16 verbose cwd C:\Users\Aaron\Examples\HapiJS\simple
17 error Windows_NT 10.0.10586
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "clean"
19 error node v5.7.0
20 error npm v3.6.0
21 error code ELIFECYCLE
22 error simple-vhost-example@1.0.0 clean: `rimraf node_modules`
22 error Exit status 1
23 error Failed at the simple-vhost-example@1.0.0 clean script 'rimraf node_modules'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the simple-vhost-example package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error rimraf node_modules
23 error You can get information on how to open an issue for this project with:
23 error npm bugs simple-vhost-example
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls simple-vhost-example
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 8
- Comments: 15 (3 by maintainers)
@IAMtheIAM’s suggestion to use
npx
is a good one, the only problem is thatnpx
attempts to use the locally installed dependencies if they exist, which causes this problem to persist. The command that actually needs to be run isnpx --ignore-existing --quiet rimraf package-lock.json node_modules
. Hope that helps someone out!@Mottie escape and use double quotes.
@Restuta @AaronNGray Can you change the script to do
rimraf "node_modules/!(rimraf|.bin)"
so that it doesn’t try to delete the thing that’s currently in use?@AaronNGray So, let me see if I understand this correctly:
rimraf
installed innode_modules
rimraf node_modules
What may be occurring here is that Windows is getting upset with you trying to unlink a file that is currently in use, and thus locked. (Unix filesystems do not have this limitation.)
@hegdeashwin I think that if your project has a(n) (in)direct dependency on
rimraf
,npm run
will prefer the version installed innode_modules/.bin
over the one installed globally. Then you’ll end up with this same issue ofrimraf
trying to delete locked files.Trying to run a script that deletes itself on Windows just isn’t a clean thing to do (unless you use whatever tricks Cygwin’s
rm
does). And ifrimraf
or any of its dependencies ever uses a lazyrequire()
you’d end up with problems from partially deletednode_modules
on any platform. You should use some tool that is not installed in your local project’snode_modules
to remove your local project’snode_modules
directory. This technique should be reliable and work on all platforms. I personally avoid writing such a script as annpm run
script in my project because I know this technique is not portable.If you choose to use
rimraf
, then to use a globally installed version (e.g. installed bynpm install -g rimraf
), you must invoke it from outside ofnpm run
. This is becausenpm run
addsnode_modules/.bin
toPATH
prior to running scripts. E.g., at the terminal you would typerimraf node_modules
instead ofnpm run clean
. If your clean step is more complicated, you could make it its own module and binary and install it globally or in another folder so that you would typemy-clean-script
instead ofnpm run clean
.@hegdeashwin @binki The notion of being able to delete node modules itself, especially on windows, has come up many times in conversation (and I think more than a few times in this issue tracker). I believe the conclusion is been that the ability to do so is outside the scope of
rimraf
, unless you want to require that it be installed globally and banish it from being installed locally (because of the preference problem).To workaround all of this, I created a separate standalone single file bundle of rimraf:
https://www.npmjs.com/package/rimraf-standalone
Follow the link above for all the details.
@isaacs yes this is exactly the case here. Idk how to deal with it though.
Glob support dropped in v4. Just give it the arguments for the thing you want deleted. Note that shell expansion is VERY different on windows from how it is on the posix shell.
I’ve encountered this issue as well. When I use the aforementioned script (https://github.com/isaacs/rimraf/issues/102#issuecomment-230588253) in the package.json file:
I’m seeing this error when the script is executed (Windows 10):
When I create a
temp.js
file, and execute it, it performs as expected:I believe that the vertical bar in the glob is being treated as a pipe. Anyone know of a way around this problem?