TL;DR — If you just installed a new version of Node, check your NPM version. If you’re using NPM v3.3.12 (the default for Node 5.5.0), you could run into issues when installing dependencies in your Sails app. Fortunately, NPM fixed this pretty fast, so all you should have to do is upgrade to the latest version of NPM (
npm install -g npm@latest) and everything will be hunky dory.
Version 3.0 of NPM (the Node Package Monger) significantly changed the way dependencies are saved in Node apps. Previously, your project’s
node_modules/ folder contained a deeply nested tree of subfolders, each representing a dependency of your project. Each one of those
node_modules/ folders contains more dependencies, each containing their own
node_modules/ folder to house their dependencies, and so on.
│ ├─┬ packageA@1.0.3 (top level dep)
│ │ ├── node_modules
│ │ │ ├── packageC@2.3.4 (2nd level dep)
│ ├─┬ packageB@0.4.5 (top level dep)
│ │ ├── node_modules
│ │ │ ├── packageC@2.3.4 (2nd level dep)etc...
This allowed for some optimizations to be made when you ran
npm install (a second-level dependency wouldn’t be installed if it matched an existing top-level dependency). But there were still a lot of redundant packages in the tree.
So NPM made some big changes. Beginning with version 3.0, all dependencies are now saved in the top-level
node_modules/ folder, unless multiple versions of the same dependency are needed:
│ ├── packageA@1.0.3
│ ├── packageB@0.4.5
│ ├── packageC@2.3.4etc...
This has the potential for a great reduction in redundancy. If your app requires both
packageB, and both of those require compatible versions of
packageC, it will only be installed once (at the top level) instead of twice (in the
node_modules/ folders of both
The NPM 3 paradigm shift has caused a few compatibility issues over time, but in the long run it was the right decision, since it reduces the amount of redundant data you need to download and store on your laptop or server when you run
npm install. To make an omelette, you have to crack some eggs. Sometimes, those eggs have little red specks in them, but that’s OK.
A bug was introduced in version 3.3.10 that under some circumstances causes NPM to incorrectly remove a dependency from the top-level
node_modules/ folder and place it further down in the tree, breaking any code that
require()s that module at the top level. The bug was patched in version 3.4.1, and using that upgrade, installs work as expected.
But be aware: at the time of writing this, the latest stable release of Node (5.5.0) comes bundled with NPM version 3.3.12, which still has the bug. To check the version of NPM you have installed, run:
If you’re using NPM v3.3.12, then you should upgrade to the patched release. To do so:
npm install -g npm@latest
Lean back, cross your legs, and enjoy the install.
The Sails.js Team
P.S. After upgrading, you should be able to
npm install in your app without further incident. But if you still see issues, it’s probably time to pull out all the stops:
- First, adjust your body into a crouching position and hold on to your desk with one hand.
- With the other hand, carefully peck out
npm install --forceon your keyboard.
<enter>, then watch the screen nervously. Try not to lose your balance. Hopefully, in a few seconds, all will be well. But if not, unleash the nuclear option with
npm cache clearand then try force installing again.
- If that doesn’t work, step away for a second. Listen to some TLC and pour yourself some sparkling grape juice. When you feel ready, continue to the next step. Only you will know when you’re ready.
- With your mind refreshed, poke around a bit in the console output from NPM and see if anything jumps out. If you’re at a loss, head over to GitHub and open an issue in the Sails repo. One of us will help you out ASAP.