Last active
July 18, 2017 15:15
-
-
Save nathansmith/bb503b48ead20805b70775ebb6e9a160 to your computer and use it in GitHub Desktop.
Force specific NPM version to be used, in a locked-down Windows environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo npm.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 | |
| @echo off | |
| "c:\program files\nodejs\X.X.X\node" --max_old_space_size=4096 "c:\program files\nodejs\X.X.X\node_modules\npm\bin\npm-cli.js" %1 %2 %3 %4 %5 %6 %7 %8 %9 | |
| @echo |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: I'm leaving instructions here, since comments aren't super intuitive in
*.batfiles:I found myself with a conundrum today.
I was working in a remotely connected Windows VM, where we have the ability to request software be installed (and uninstalled) via IT department, but cannot ourselves do "admin" type actions such as uninstall.
I needed to force a specific version of NPM to be used, while there were multiple versions installed. However, Windows kept picking up on an out-of-date version as the default for
npm run …. Without being able to manually remove that older version, I had to get creative.My coworker showed me this trick, adding the hard-coded path for a desired NPM version into a
npm.batfile.When you
cdinto the project directory and type……then Windows will see the
npm.batfile and use it instead of the globally installed NPM.With this file, we are basically telling Windows: Always use version
X.X.Xwhere those X's denote the semantic version.http://semver.org
Essentially, this allows you to intercept the
npmcommand, alias it on the fly to the correct version, and then continue running any other parameters that have been passed:%1,%2, etc.(Add more as needed:
%10,%11, …)