Fix NVM_NODEJS_ORG_MIRROR deprecation warning when running npm install

By: (plus.google.com) +David Herron; Date: April 10, 2018

Tags: Node.JS

The nvm script is an exceedingly useful tool for maintaining multiple Node.js versions while keeping your sanity. Running "npm install", I noticed a strange warning message from node-gyp about "NVM_NODEJS_ORG_MIRROR" being deprecated. Looking for the cause, I found a cause centered on nvm. Let's see how to fis this problem.

What is nvm and why is it needed?

Probably the best method for installing and updating Node.js is to install packages through the package manager for your operating system. That's easy, you type sudo port install nodejs or sudo apt-get install nodejs or some equivalent, and from that point onward the packaging system maintainers keep you up-to-date.

What if your operating system does not have Node.js packages available? What if Node.js packages are available, but they're woefully out of date? What if you need to support several Node.js versions, and are routinely switching between them?

That's what nvm is meant to solve. It simplifies maintaining multiple side-by-side Node.js installs, and lets you easily switch between Node.js versions.

To install, go to: (github.com) https://github.com/creationix/nvm

Then pick your preferred installation command between these two:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

Make sure to go to the Github page to get the latest version number rather than the number shown here.

After running the command, you'll be given a code snippet to add to your $HOME/.bashrc or $HOME/.profile so that nvm is available to every command shell.

Once that's setup you can install a Node.js version by running nvm install 9 (to get the latest Node.js 9.x) or whatever. The github page has full information.

What's it mean that NVM_NODEJS_ORG_MIRROR is deprecated?

Let's now talk about the deprecation message causing me to write this posting.

I got npm install output for a project reading:

$ npm install
npm WARN registry Using stale data from https://registry.npmjs.org/ because the host is inaccessible -- are you offline?
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.

> dtrace-provider@0.8.6 install /Volumes/Extra/book-4th/chap09/users/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  ACTION binding_gyp_ndtp_target_build_ndtp .
  TOUCH Release/obj.target/ndtp.stamp

> sqlite3@3.1.13 install /Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

[sqlite3] Success: "/Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3/lib/binding/node-v59-darwin-x64/node_sqlite3.node" is installed via remote
npm WARN user-auth-server@0.0.1 No description
npm WARN user-auth-server@0.0.1 No repository field.

added 232 packages in 24.384s

The warning about NVM_NODEJS_ORG_MIRROR being deprecated and such was irksome, and I wanted to find the solution.

After some searching, I got to this issue: (github.com) https://github.com/creationix/nvm/issues/1429

This is where the nvm maintainers fixed the deprecation warning. The discussion refers to earlier features in node-gyp - that node-gyp formerly paid attention to environment variables placed by nvm.

This node-gyp issue discussed the warning: (github.com) https://github.com/nodejs/node-gyp/issues/942

Sometime in early 2016, the node-gyp tool began printing that message and there was an effort to work with the nvm maintainer to get the two in sync. That node-gyp paid attention to nvm environment variables was a bug.

BTW, node-gyp is the tool used by Node.js and npm to build native-code packages. We generally don't directly run node-gyp but instead it is run as a side effect of installing packages requiring compilation using node-gyp.

To cut to the chase -- the nvm issue made it clear that nvm fixed this problem in early 2017. The question then is why does this message still get printed?

$ ls -l $NVM_DIR/nvm.sh
-rwxr-xr-x  1 david  staff  70948 Feb  8  2016 /Users/david/.nvm/nvm.sh

This is why -- my nvm was very much out of date.

Another piece of data is these environment variables:

$ env | grep MIRROR
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist

If one unsets those variables, then reruns . $NVM_DIR/nvm.sh those variables get reinitialized. Unset the variables, then rerun npm install and the deprecation warnings are not printed.

We have already seen the solution. At the nvm Github page we see that the install script can also be used to update an existing nvm installation.

Therefore fixing the problem is easy enough. Just rerun the nvm installer, and then update the $HOME/.profile and $HOME/.bashrc files because there is a new initialization script. All of which is explained here:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12540  100 12540    0     0  12540      0  0:00:01  0:00:01 --:--:--  7437
=> nvm is already installed in /Users/david/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> Appending nvm source string to /Users/david/.bashrc
=> Appending bash_completion source string to /Users/david/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Having done the above, and rerunning . $NVM_DIR/nvm.sh, neither of those environment variables exist. And we get this clean output from npm install

$ ls -l $NVM_DIR/nvm.sh
-rw-r--r--  1 david  staff  108382 Apr 10 13:16 /Users/david/.nvm/nvm.sh
$ . $NVM_DIR/nvm.sh
$ env | grep MIRROR
$ rm -rf node_modules/ 
$ npm install

> dtrace-provider@0.8.6 install /Volumes/Extra/book-4th/chap09/users/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

  ACTION binding_gyp_ndtp_target_build_ndtp .
  TOUCH Release/obj.target/ndtp.stamp

> sqlite3@3.1.13 install /Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

[sqlite3] Success: "/Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3/lib/binding/node-v59-darwin-x64/node_sqlite3.node" is installed via remote
npm WARN user-auth-server@0.0.1 No description
npm WARN user-auth-server@0.0.1 No repository field.

added 232 packages in 24.74s
« Use Bash-like command-line environment variables on Windows in Node.js npm scripts Implementing __dirname in ES6 modules using import.meta.url »
2016 Election Acer C720 Ad block AkashaCMS Amazon Amazon Kindle Amazon Web Services America Amiga and Jon Pertwee Android Anti-Fascism AntiVirus Software Apple Apple Hardware History Apple iPhone Apple iPhone Hardware April 1st Arduino ARM Compilation Artificial Intelligence Astronomy Astrophotography Asynchronous Programming Authoritarianism Automated Social Posting AWS DynamoDB AWS Lambda Ayo.JS Bells Law Big Brother Big Data Big Finish Big Science Bitcoin Mining Black Holes Blade Runner Blockchain Blogger Blogging Books Botnets Cassette Tapes Cellphones China China Manufacturing Christopher Eccleston Chrome Chrome Apps Chromebook Chromebox ChromeOS CIA CitiCards Citizen Journalism Civil Liberties Clinton Cluster Computing Command Line Tools Comment Systems Computer Accessories Computer Hardware Computer Repair Computers Conservatives Cross Compilation Crouton Cryptocurrency Curiosity Rover Currencies Cyber Security Cybermen Daleks Darth Vader Data backup Data Formats Data Storage Database Database Backup Databases David Tenant DDoS Botnet Department of Justice Detect Adblocker Developers Editors Digital Photography Diskless Booting Disqus DIY DIY Repair DNP3 Do it yourself Docker Docker MAMP Docker Swarm Doctor Who Doctor Who Paradox Doctor Who Review Drobo Drupal Drupal Themes DVD E-Books E-Readers Early Computers Election Hacks Electric Bicycles Electric Vehicles Electron Eliminating Jobs for Human Emdebian Encabulators Energy Efficiency Enterprise Node EPUB ESP8266 Ethical Curation Eurovision Event Driven Asynchronous Express Face Recognition Facebook Fake News Fedora VirtualBox Fifth Doctor File transfer without iTunes FireFly Flash Flickr Fraud Freedom of Speech Front-end Development Gallifrey git Github GitKraken Gitlab GMAIL Google Google Chrome Google Gnome Google+ Government Spying Great Britain Green Transportation Hate Speech Heat Loss Hibernate Hoax Science Home Automation HTTP Security HTTPS Human ID I2C Protocol Image Analysis Image Conversion Image Processing ImageMagick In-memory Computing InfluxDB Infrared Thermometers Insulation Internet Internet Advertising Internet Law Internet of Things Internet Policy Internet Privacy iOS Devices iPad iPhone iPhone hacking Iron Man iTunes Janet Fielding Java JavaFX JavaScript JavaScript Injection JDBC John Simms Journalism Joyent Kaspersky Labs Kindle Kindle Marketplace Large Hadron Collider Lets Encrypt LibreOffice Linux Linux Hints Linux Single Board Computers Logging Mac Mini Mac OS Mac OS X Machine Learning Machine Readable ID macOS MacOS X setup Make Money Online March For Our Lives MariaDB Mars Mass Violence Matt Lucas MEADS Anti-Missile Mercurial MERN Stack Michele Gomez Micro Apartments Microsoft Military AI Military Hardware Minification Minimized CSS Minimized HTML Minimized JavaScript Missy Mobile Applications Mobile Computers MODBUS Mondas Monetary System MongoDB Mongoose Monty Python MQTT Music Player Music Streaming MySQL NanoPi Nardole NASA Net Neutrality Network Attached Storage Node Web Development Node.js Node.js Database Node.js Performance Node.js Testing Node.JS Web Development Node.x North Korea npm NVIDIA NY Times Online advertising Online Community Online Fraud Online Journalism Online Photography Online Video Open Media Vault Open Source Open Source Governance Open Source Licenses Open Source Software OpenAPI OpenJDK OpenVPN Palmtop PDA Patrick Troughton Paywalls Personal Flight Peter Capaldi Peter Davison Phishing Photography PHP Plex Plex Media Server Political Protest Politics Postal Service Power Control President Trump Privacy Production use Public Violence Raspberry Pi Raspberry Pi 3 Raspberry Pi Zero ReactJS Recaptcha Recycling Refurbished Computers Remote Desktop Removable Storage Republicans Retro Computing Retro-Technology Reviews RFID Rich Internet Applications Right to Repair River Song Robotics Robots Rocket Ships RSS News Readers rsync Russia Russia Troll Factory Russian Hacking Rust SCADA Scheme Science Fiction SD Cards Search Engine Ranking Season 1 Season 10 Season 11 Security Security Cameras Server-side JavaScript Serverless Framework Servers Shell Scripts Silence Simsimi Skype SmugMug Social Media Social Media Warfare Social Network Management Social Networks Software Development Space Flight Space Ship Reuse Space Ships SpaceX Spear Phishing Spring Spring Boot Spy Satellites SQLite3 SSD Drives SSD upgrade SSH SSH Key SSL Stand For Truth Strange Parts Swagger Synchronizing Files Tegan Jovanka Telescopes Terrorism The Cybermen The Daleks The Master Time-Series Database Tom Baker Torchwood Total Information Awareness Trump Trump Administration Trump Campaign Twitter Ubuntu Udemy UDOO US Department of Defense Virtual Private Networks VirtualBox VLC VNC VOIP Vue.js Walmart Web Applications Web Developer Resources Web Development Web Development Tools Web Marketing Webpack Website Advertising Weeping Angels WhatsApp William Hartnell Window Insulation Windows Windows Alternatives Wordpress World Wide Web Yahoo YouTube YouTube Monetization