npm installing itself without dependancies - node.js

I am trying to install the latest npm, following the instructions on the npm doc site.
My problem is that using command:
npm install -g npm
to get the latest version of NPM does not seem to work: it does not seem to install any of the needed dependencies, so when I run it I get errors such as:
module.js:340
throw err;
^
Error: Cannot find module 'are-we-there-yet'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/harmic/.node_modules/lib/node_modules/npm/node_modules/npmlog/log.js:2:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I am using a Centos 6 machine, so I started by installing node + npm from EPEL, like this:
yum install nodejs npm
That went OK. I then went to install the latest npm, as recommended at the above link and many other pages I've seen. My first attempt
sudo npm install -g npm
was not so great, for two reasons:
It installed in /usr/lib/node_modules, over the top of the original RPM installation. I judged this to be extremely poor practice, because the next time I did yum update on the system there was every chance the newly installed files would be overwritten by whatever incoming RPM packages contained, leaving an unholy mess.
It did not work anyway: I could not start npm at all, it constantly complained of missing dependancies as described above.
So I uninstalled the RPMs, removed all the left over files, then reinstalled the RPMs again. This time I created a ~/.npmrc file and put this in it:
prefix = ${HOME}/.node_modules
I also set NODE_PATH environment variable to include that path. After this, npm did install itself in my desired location, but did not install any dependencies:
$ npm install -g npm
npm http GET https://registry.npmjs.org/npm
npm http 304 https://registry.npmjs.org/npm
/home/harmic/.node_modules/bin/npm -> /home/harmic/.node_modules/lib/node_modules/npm/bin/npm-cli.js
npm#3.3.3 /home/harmic/.node_modules/lib/node_modules/npm
Running it from the new installed path gave the error at the top of the page.
Despite thinking that I must be doing something seriously wrong, I set about trying to install the unmet dependencies, one at a time:
npm install -g are-we-there-yet
npm install -g gauge
npm install -g os-tmpdir
npm install -g os-homedir
npm install -g is-absolute
npm install -g asap
npm install -g path-is-absolute
npm install -g builtins
npm install -g validate-npm-package-license
npm install -g concat-stream
npm install -g json-parse-helpfulerror
npm install -g readdir-scoped-modules
npm install -g debuglog
npm install -g lodash._baseclone
npm install -g lodash._bindcallback
npm install -g lodash._baseflatten
npm install -g lodash._baseuniq
...
and still it complains about needing more.
Finally I have concluded that I must have missed something important, so I decided to ask for the help of the SO community...
The initially installed versions of node & npm RPMs are:
nodejs-0.10.36-3.el6
npm-1.3.6-5.el6
Oh and in case you are wondering, the reason I am trying to update npm in the first place is because when trying to install this package I ran into a build error, the solution to which is apparently to install an updated npm.

First of all I would suggest you to forget to install node with RPM/APT etc, the reason for this is because normally they have outdate versions. Infact 0.10 is very old, 0.12 is nearly a year old and now there's 4.1 already. So my suggestion is to use nvm https://github.com/creationix/nvm
nvm is a Node Version Manager. the cool think is that you can switch version with a single command and stay always updated. After installing the node version that you want, you can also upgrade npm.
You can even select a node version for a certain folder in your system (if you have code that runs just in an old version for example)

Related

#angular/cli not working after installation

I have installed the #angular/cli on my MacBook machine. Node server version is v6.9.5 and the npm version is 3.10.10. I have ran the following command to install the #angular/cli.
sudo npm install -g #angular-cli
When I run the ng help command or any command for ng. It shows me the following error
Parsing .angular-cli.json failed. Please make sure your .angular-cli.json
is valid JSON.
Error: SyntaxError: Unexpected token u in JSON at position 22
InvalidConfigError: Parsing .angular-cli.json failed. Please make sure your
.angular-cli.json is valid JSON.
Error: SyntaxError: Unexpected token u in JSON at position 22
at InvalidConfigError (/usr/local/lib/node_modules/#angular/cli/models/config/config.js:10:9)
at Function.fromConfigPath (/usr/local/lib/node_modules/#angular/cli/models/config/config.js:77:19)
at Function.fromProject (/usr/local/lib/node_modules/#angular/cli/models/config.js:96:46)
at Object.<anonymous> (/usr/local/lib/node_modules/#angular/cli/commands/build.js:7:35)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
I also uninstalled and #angualr/cli and clear the cache then reinstalled #angualr/cli. I run the following command.
sudo npm uninstall -g #angular-cli
npm cache clean sudo
npm install -g #angular-cli
Still the same issue is appearing.
The package is called #angular/cli, so do npm install -g #angular/cli.
#angular-cli is the previous version. Now you need to
npm install -g #angular/cli
to work with #angular/cli version
The package you mentioned is not valid. For fresh installation use npm install -g #angular/cli.
Check here for more details https://github.com/angular/angular-cli#installation
Also If you are upgrading follow this https://github.com/angular/angular-cli#updating-angular-cli
If you upgrading from a beta/RC version follow this https://github.com/angular/angular-cli/wiki/stories-1.0-update
angular-cli uses angular.cli.json.
whereas #angular/cli uses .angular.cli.json
i also face same issue, so i tried this method given below.
Clean uninstall of angular-cli, like npm uninstall -g angular-cli
Clone this angular-cli repo,
Go to the angular-cli repo folder, and run npm link,
Go to my project folder
Run npm link angular-cli
Now to run ng command, I use ./node_modules/angular-cli/bin/ng from my project folder
You need to install #angular/cli globally to use it anywhere.To install it globally use cmd 'npm i -g #angular/cli',where -g means globally.Even update your angular version to latest.I think the error is because in older versions of angular,the angular.json file name used to be saved differently and its name is differently saved in newer or latest versions,so after installation it might not be able to read your angular.json file.

Ionic installation after Ionic2 installation

I tried to install Ionic2 with no success, so I decided to go back to Ionic but during the process something went bad and I can't re-installl the ionic and cordova.
after sudo npm install -g cordova ionic, I tried to run ionic and got:
xx#xxx:~/dev$ ionic info
module.js:328
throw err;
^
Error: Cannot find module 'xmlbuilder'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/ionic/node_modules/xml2js/lib/xml2js.js:12:13)
at Object.<anonymous> (/usr/local/lib/node_modules/ionic/node_modules/xml2js/lib/xml2js.js:436:4)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
my versions are:
xx#xxx:~/dev$ npm -v
2.14.12
gal#xxx:~/dev$ nodejs -v
v0.10.25
xx#xxx:~/dev$ node -v
v4.2.6
I also encountered that issue. What I did was:
$ cd /usr/local/lib/node_modules/ionic/
$ npm install xmlbuilder
You may also use sudo
It just happens that xmlbuilder is a dependency of xml2js and cannot load the module because it wasn't included in the ionic's package.json of the upon installing ionic.
What worked for me was to use
sudo npm install -g ionic#beta cordova
to install the V2 version according to link.
Cleaning the npm cache helped in my case. The actions required were:
Install a stable version of nodejs depending of your OS follow these instructions.
Remove all installed versions of cordova and ionic:
sudo npm uninstall -g ionic cordova bower
Critically, clean the npm cache:
npm cache clean
Install from scratch:
sudo npm install bower cordova ionic -g
NOTE: Do not install nodejs version from Ubuntu 14.04 LTS repository because is outdated.
Have you tried to
sudo npm uninstall -g ionic
sudo npm install -g ionic
I faced similar issues while downloading ionic 2. Try to install node version 4.2.3 and cordova version 5.4.1 first and then install ionic
For ionic v2, npm install -g ionic#beta
For ionic v1, npm install -g ionic
You should check your version of nodejs. Make sure that it's version 4. If not, uninstall nodejs and install ver 4.
Goodluck!
P/s:
Uninstall:
sudo apt-get remove nodejs
Install:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

Error "Cannot find module 'npmlog'" after "npm update -g"

I have NVM 0.30.1 and used it to install node.js v5.4.0 (with NPM 3.5.4) on Fedora 22. When I run npm update -g, I receive the following warnings:
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > init-package-json with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > node-gyp with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npm-install-checks with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npmlog with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > read-package-json with new installed version
And after that, when I run npm I get this error:
module.js:328
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:20:13
at Object.<anonymous> (/home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:76:3)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
Does anyone know what it is and how to solve it?
Thanks
What fixed this for me was
sudo rm -rf /usr/local/lib/node_modules/
and then re-installing node (with npm).
Thanks for the answers. It was a bug and it has already been fixed in Node v5.4.1. Now it's working as usual.
It looks like npm update -g cannot update npm to the newest version. I solve the problem by updating npm installation manually.
Install/ reinstall node to get the bundled npm
run npm install -g npm#3.5.4 to update the global npm installation
now npm update -g should work
I have faced the same issue in my Windows 10 PC. After looking into solutions, since i couldn't find the exact solution for the issue i was facing
Cannot find module 'npmlog'
I just uninstalled the node js and then, deleted both 'npm' and 'npm-cache' in
"C:\Users\YourPCName\AppData\Roaming"
Then, i downloaded the latest version of node from Node JS Website
And, installed node js
After that i checked with the path in environment variables.
Finally run the command prompt 'run as administrator' and npm install npm -g
Checking your version will show the latest version. 'npm -v'
I got the latest version - v3.10.9
Try this. this should work.
If people with linux are facing the problem, here is the solution:
As of the date of this post, the NPM version packaged with Nodejs doesn't work. If you installed this package, run
sudo rm -rf /usr/local/bin/npm
sudo apt-get install node
sudo mv /usr/bin/npm /usr/local/bin/npm
New version should be 3.10.8 and the old error gone
init-package-json, node-gyp, npm-install-checks, npmlog, read-package-json didn't installed correctly. Not sure why though.
Didn't find the root cause for the issue but I used the hacky way to install the packages above for now:
Roll back to the previous node version which npm didn't be updated. For example, nvm use iojs
cd to where npm installed, for example, cd /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm and reinstall those packages like rm -rf node_modules/init-package-json && npm install init-package-json etc.
Some of the answers already answered the question, but I will still like to throw in my own idea. I encountered same issue after I was told to run npm update -g npm after running that piece of code, the error started. I solved mine by using Node Version Manager(nvm):
nvm install 8
Note: not actually 8, but to a version of your choice e.g(6,5). Writing the version number will automatically install the stable of the version specified.
After the installation you should get a CLI message:
Now using node v8.11.4 (npm v5.6.0)
If you're using a Mac, perform the following steps, to remedy (assuming you have Homebrew installed already):
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
(to overcome bash: /usr/local/bin/npm: No such file or directory error):
hash -r
Then go ahead with updating brew (to keep its kegs up to date) and the reinstallation process, linking is optional.
brew update
brew reinstall node
brew link --overwrite node
At any point inbetween you can use npm -v or node -v to test whether or not you are making progress. If you have node returning a version, but not npm then you will need to add your path to your environment with:
export PATH="/usr/local/bin:$PATH"
There is an option to bump npm without reinstalling node.
#### # this will remove current npm
rm -rf /usr/local/lib/node_modules/npm/
#### # install npm from sources. Version 3.5.x will be installed
apt-get update
apt-get install npm
#### # install the newest npm version. Bumping from 3.5.X to 6.14.X goes without any issue :)
/usr/bin/npm install npm#latest -g
#### # additionally, npm with version 3.5.x is not added to $PATH, so it's not used.

npm install less but can't require via node

mac os x 10.10.5
my node and npm version.
node -v
v4.2.1
npm -v
2.14.7
then refer to official website I install less.
sudo npm install -g less
sudo npm install -g less-plugin-clean-css
and I confirm that successfully installed in node_modules
ls /usr/local/lib/node_modules/
appcelerator generator-webapp ios-sim yo
bower grunt-cli less
cordova gulp less-plugin-clean-css
express ionic npm
but when I use node command line to require less, some error occured..
> var less = require('less')
Error: Cannot find module 'less'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at repl:1:12
at REPLServer.defaultEval (repl.js:164:27)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:393:12)
at emitOne (events.js:82:20)
>
I google it but find nothing which could solve it, please some help ..
require doesn't load global modules by default. the modules must be located in the local node_modules folder.
If you really want to use global modules, you can set the NODE_PATH env variable (but this is bad practice in my opinion):
export NODE_PATH=/usr/local/lib/node_modules/
Here is some background information.
i think your less module in not install perfectly,
As you used command sudo npm install -g less It install Less module globally,
Now you redirect your terminal to your project folder and Use the Following Command sudo npm install less ,remember use it without using -g.
For more information you can visit the enter link description here
I'm install it locally, without '-g' flag in working folder and now it works.
You should open issue on their gitbug if you want to install it correctly globally.

Nodejs and npm error. modules missing

module.js:340
throw err;
^
Error: Cannot find module 'vinyl'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/morpheyesh/debugall/web-starter-kit/node_modules/gulp/node_modules/gulp-util/lib/File.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I have major issues with node.js. I try to run any nodejs application or gulp, i get this error, I try to install every module , I keep getting the same error and it requires a new module. Is there anyway where I can install all the modules?
Plus, I have install nodejs through npm? how to install system wide? Gulp is been installed system wide(global). What is causing this error?
nodejs -v gives v0.10.30
`npm -v gives 1.4.21
gulp 3.8.7
I am working with the google web starter kit. I installed nodejs using apt-get, then install sass, then installed gulp, then npm. Is there a way where I can remove all these and install all of it system wide?
Try updating your global gulp installation:
sudo npm install --global gulp#latest
It sounds like everything is (was?) FUBAR for a while there. If you have not yet solved these problems, here's what I would recommend.
First, the official (Debian/Ubuntu) packages are a bit behind latest node. I would recommend uninstalling the packages nodejs and nodejs-legacy and following the instructions here to get the latest versions (packaged and published by nodesource): https://github.com/nodesource/distributions#usage-instructions
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
Now you will have a recent node (0.10.35) but an out-of-date npm. Upgrade your npm:
npm install -g npm#latest
Things should now work for you; you should be able to run npm install in your project directory and all dependencies will be installed correctly.
One thing to be wary of is that you should never run npm update or npm update -g. This does not update the current (or all global) packages, as one might think.
Try this for install all plugins required by gulp :
npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev
Source : http://travismaynard.com/writing/getting-started-with-gulp
For me uninstalling gulp and then reinstalling it worked fine. This is with node v5.0.0
sudo npm uninstall -g gulp
npm install -g gulp

Resources