-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrading node-gyp independently of npm and handling multiple versions #2272
Comments
We could also mention that you can achieve the same thing by setting the env var |
@liuliangsir Your issue is related to #661 #2058 #2110 #2112 |
@cclauss okay, thanks! |
I think that should be added to node-gyp's wiki |
I need help!!!!!! npm ERR! code 1 npm ERR! A complete log of this run can be found in: |
https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md |
Hi, the solution above did not work for me. I am running Linux. |
@technoken35 hi. Tell us your environment (versions):
Also send your npm config file |
I also have npm installed via homebrew. I'm not sure if you want to see the user config or so I placed contents of both. Node - 16.9.2 contents of user config contents of built in |
Python 2 died 623 days ago on 1/1/2020 so node-gyp is no longer compatible with it. Current Python is 3.9.7. https://www.python.org/downloads/ |
@cclauss I wasn't using python 2 when I ran the command
|
Edit user config to remove Py2.
https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md |
Changed to python 3. Looked at the logs and noticed something weird. |
Yes. That is why you should do the process in the URL that I provided above. |
(This could be made into a top-level doc, or integrated into the README, it comes up enough. Please edit this post or comment below if you have improvement suggestions. If someone wants to turn this into a PR then you're welcome to.)
Wot?
npm ships with its own version of node-gyp. Older versions of npm have older versions of node-gyp. npm has caught up recently to node-gyp's release cycle but it's expected we'll get out of sync and there will be cases where you need an old npm but a newer node-gyp, or npm doesn't ship yet with a node-gyp that we've released and it has fixes you need.
Generally, npm's library files are installed inside your global "node_modules", where npm is installed (run
npm prefix
and addlib/node_modules
, or justnode_modules
for Windows [I think, Windows person - please confirm and edit this]). There are some exceptions to this. Inside this globalnode_modules/
there will be annpm/
directory and inside this you'll find anode_modules/node-gyp/
directory. So it may look something like/usr/local/lib/node_modules/npm/node_modules/node-gyp/
. This is the version of node-gyp that ships with npm.When you install a new version of node-gyp with outside of npm, it'll go into your global node_modules, but not under the
npm/node_modules
. So that may look like/usr/local/lib/node_modules/node-gyp/
. It'll have thenode-gyp
executable linked into yourPATH
so runningnode-gyp
will use this version.The catch is that npm won't use this version unless you tell it to, it'll keep on using the one you have installed. You need to instruct it to by setting the
node_gyp
config variable (which goes into your~/.npmrc
). You do this by running thenpm config set
command as below. Then npm will use the command in the path you supply whenever it needs to build a native addon.Important: You also need to remember to unset this when you upgrade npm with a newer version of node-gyp, or you have to manually keep your globally installed node-gyp to date. See "Undo" below.
Linux and macOS
sudo
may be required for the first command if you get a permission error.Windows
@joaocgreis' Windows instructions from #1753 (comment)
Windows Command Prompt
Powershell
Undo
Beware if you don't unset the
node_gyp
config option, npm will continue to use the globally installed version of node-gyp rather than the one it ships with, which may end up being newer.The text was updated successfully, but these errors were encountered: