Error when using npm - node.js

I get the following error when trying to use npm on mac. I'm on mac 10.10.1
$ npm
Error: ENAMETOOLONG, mkdir '/Users/LM/npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli '-g',
npm verb cli 'config',
npm verb cli 'get',
npm verb cli 'prefix' ]
npm info using npm#2.1.6
npm info using node#v0.10.33
npm verb node symlink /usr/local/bin/node
/Users/LM/Desktop/Titanium Studio/TitaniumStudio.app/Contents/MacOS/npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli '-g',
npm verb cli 'config',
npm verb cli 'get',
npm verb cli 'prefix' ]
npm info using npm#2.1.6
npm info using node#v0.10.33
npm verb node symlink /usr/local/bin/node
/Users/LM/Desktop/Titanium Studio/TitaniumStudio.app/Contents/MacOS/npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli '-g',
npm verb cli 'config',
npm verb cli 'get',
npm verb cli 'prefix' ]
npm info using npm#2.1.6
npm info using node#v0.10.33
npm verb node symlink /usr/local/bin/node
/usr/local
npm verb exit [ 0, true ]
npm info ok
npm verb exit [ 0, true ]
npm info ok
npm verb exit [ 0, true ]
npm info ok'
Any ideas what this means and how to fix?

I think the issue is due to the permissions. Try to change the permissions as followed :
Unlock permissions in your home directory.
sudo chown -R `whoami` ~/.npm
If 1 does not work, get write permissions to the node_modules directory.
sudo chown -R `whoami` /usr/local/lib/node_modules
If you still face error, update permission of /usr/local.
sudo chown -R `whoami` /usr/local
Hope it helps.

The error ENAMETOOLONG means that nodejs (or the OS) is trying to use a pathname component that exceeds your OS's maximum (in the case of OSX, 31).
Firstly where have you tried to install nodejs from? This could be the cause of your issue. I've never used Titanium Studio but your question reads like this is the intall of nodejs that you are using.
You may be best installing node directly from github. The following should get you started.
Install Node
mkdir ~/src
cd ~/src
git clone https://github.com/joyent/node.git
cd node
git checkout v0.10.33
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
Dont forget to add $HOME/local/node/bin to your PATH enviromental variable.
You can test your node installation by
node -v
Install NPM
curl http://npmjs.org/install.sh | sh
You can test your npm installation by
npm -v

There are several solutions suggested here, where somebody has the exact same problem, also using titanium studio: https://developer.appcelerator.com/question/179230/unable-to-properly-update-titanium-studio
Manually updating CLI, Node.ACS, and Alloy
sudo npm install -g alloy#1.5.1
sudo npm install -g titanium#3.4.1
sudo npm install -g acs
Change permissions to the directory
sudo chown -R whoami ~/.npm
Although it seems that the last thing did not work. You might want to have a look here as well: NPM throws error without sudo

1. Discover where npm executables exist
First, find out where npm executables exist on your system:
$ which -a npm
This should output two or more system paths.
2. Find out your shell's $PATH
Then, determine the search paths for your command execution:
$ echo $PATH
This will give you a colon-separated list of directories your session is searching for executables like npm.
3. Give priority to a different npm
Appcelerator Titanium has corrupted one or more aspects of your system. You may want to temporarily uninstall Titanium.
Otherwise, to give preference to another Node.js installation, you can edit your $PATH or even more simply, create a shell alias. For example:
$ alias npm=/usr/local/bin/npm
In most cases, you can "save" this in your ~/.bash_profile file (by simply copying and pasting the text as if you were at the prompt) so that it's applied to future shell sessions.

Related

Issue with webpack and npm package installation in ubuntu

I was suddenly having an issue in my project like this.
It was repeated and crashed my chrome:
So, I downgraded some of my packages and I downgraded my npm to 6.6.0 which was stable for my project. The main problem started after that. I removed the node_modules folder and when I tried to
sudo npm install [because npm install says permission issue]
it started showing these errors:
npm info it worked if it ends with ok npm verb cli [ '/usr/bin/node',
npm verb cli '/data/data/com.termux/files/usr/bin/npm', npm verb cli
'i', npm verb cli '-g', npm verb cli 'npm', npm verb cli
'--verbose' ] npm info using npm#6.6.0 npm info using node#v10.15.0 npm
verb npm-session 3b7ba2a77f7e848c Unhandled rejection Error: EACCES:
permission denied, link '/home/.npm/_cacache/tmp/6a547224' ->
'/home/.npm/_cacache/content-v2/sha512/d8/e0/f8cb9554c1f6f974b32fe943e4df8353fca3cb4843dbeda6fe0d88d14eb91bec5d23ddde1751af76721044d662b479ec4c9df9f0bfcce592bbc9fc2b6f72'
at Error (native)
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error
at: npm ERR! https://github.com/npm/npm/issues
npm ERR! A complete log of this run can be found in: npm ERR!
/home/.npm/_logs/2017-06-28T00_20_47_543Z-debug.log
I have also tried npm cache clear -f
and also tried to install npm install --no-cache
But it was having problem with npm install and somehow I was getting the previous build.
I have solved this issue by changing the permission level of my user. This was an issue because in ubuntu the node_modules folder had by default root folder permission. I have checked this by this command:
in my project folder: ls -la
So I got a whole list where I have seen the permission for node_modules was like this:
drwxrwsrwx 906 root www-data 36864 মে 14 16:17 node_modules
-rw-r--r-- 1 my_username www-data 2407 মে 14 16:14 package.json
But my user didn't have the permission to write.
So what I did is:
sudo chown -R my_username:my_username node_modules/
It solved my problem.

NPM install permission denied error using root user

So I've made a fresh installation of npm/node on my local machine using NVM using root user and everything looks fine, now my issue is when I tried to install using npm install --unsafe-perm -verbose command on my project folder error displays in my terminal.
npm verb stack Error: Command failed: /usr/bin/git clone --depth=1 -q -b 0.0.7 https://github.com/Mango/emitter.git /root/.npm/_cacache/tmp/git-clone-28a98ad9
npm verb stack fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-28a98ad9': Permission denied
npm verb stack
npm verb stack at ChildProcess.exithandler (child_process.js:282:12)
npm verb stack at ChildProcess.emit (events.js:182:13)
npm verb stack at maybeClose (internal/child_process.js:957:16)
npm verb stack at Socket.stream.socket.on (internal/child_process.js:378:11)
npm verb stack at Socket.emit (events.js:182:13)
npm verb stack at Pipe._handle.close [as _onclose] (net.js:598:12)
npm verb cwd /web/nbltv
npm verb Linux 4.15.0-29-generic
npm verb argv "/root/.nvm/versions/node/v10.1.0/bin/node" "/root/.nvm/versions/node/v10.1.0/bin/npm" "install" "--unsafe-per" "-verbose"
npm verb node v10.1.0
npm verb npm v5.6.0
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b 0.0.7 https://github.com/Mango/emitter.git /root/.npm/_cacache/tmp/git-clone-28a98ad9
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-28a98ad9': Permission denied
npm ERR!
npm verb exit [ 1, true ]
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-08-20T01_36_33_496Z-debug.log
NPM version - 5.6
NODE version - 10.1
Any help would be much appriciated. Thanks!
Chown down your node_modules & do not run as sudo.
You should always have ownership of the .npm directory as NPM will refuse installing native modules with sudo as this can be a security risk.
Try sudo chown -R $(whoami) ~/.npm and see if this would work. (or sudo chown -R $(whoami) ~/.nvm if you're using nvm)
Or reinstall with a node version manager without root as recommended in the docs:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Creating a new global storage in your user space is the recommended way of preventing this error. Don't use sudo or change ownership of locations.
$ mkdir ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ export PATH=~/.npm-global/bin:$PATH
$ source ~/.profile
However, since you're using npm 5.6, this might be more relevant to you:
npx: an alternative to running global commands
If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.
Source: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
#U-ways answer is very good but for people who use nvm
rather than:
sudo chown -R $(whoami) ~/.npm
do
sudo chown -R $(whoami) ~/.nvm
this works form me
This works for me
sudo chown -R $(whoami) ~/.npm

child_process.exec/spawn triggers callback/close with npm install command (via Gulp / Shipit)

I'm using Shipit for deployment.
On deploy, Shipit checks out the current Git Sha, to a tmp directory, then I run npm install followed by gulp build, then proceed with the deploy.
Shipit uses Orchestrator for it's task flow, as Gulp does.
Shipit has it's own CLI, so I can deploy with shipit development deploy.
Everything thing above works. What I'm trying to do is create a gulp deploy task that will initialize Shipit directly, instead of using the CLI. Looks something like this:
gulp.task('shipit:deploy', function() {
var deployToEnv = argv['deploy-to'] || false;
var shipit;
return inquirer.prompt([{
type: 'list',
name: 'deployToEnv',
default: deployToEnv,
message: 'Deploy to environment:',
choices: envs
}]).then(function(answers) {
deployToEnv = answers.deployToEnv;
shipit = new Shipit({environment: deployToEnv});
shipit.initialize();
shipit.start('deploy');
});
});
Corresponding shipit config:
shipit.initConfig(config);
shipit.blTask('build', function() {
return shipit.local('npm install --silent', {
cwd: shipit.config.workspace
}).then(function() {
return shipit.local('gulp build', {
cwd: shipit.config.workspace
});
});
});
shipit.on('fetched', function() {
shipit.start('build');
});
Things appear to work with one problem: it doesn't actually perform the npm install!
Running "npm install --silent" on local.
Running "gulp build" on local.
So, it would seem something in the npm install command is prematurely resolving the promise, but I'm not sure how or why.
I had a similar problem (just using shipit cli) with npm warnings, which is when I discovered using the --silent arg solved that.
As a test, I left the code as is, but replaced npm install --silent with sleep 10. Sure enough, it waited for 10 seconds before executing gulp build. So, it would seem it is something specific with the npm install command.
Any help is appreciated!
Update #1:
shipit.local uses child_process.exec. I tried converting this to use child_process.spawn, but had the same result.
Update #2:
If I change the command to sudo npm install, things work as expected! So...what does this mean, and how can I avoid running it with sudo?
Update #3:
Still unable to do this without sudo, but I tried adding the --verbose flag with these results:
Without sudo:
# npm info it worked if it ends with ok
# npm verb cli [ '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/node',
# npm verb cli '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm',
# npm verb cli 'install',
# npm verb cli '--verbose' ]
# npm info using npm#2.5.1
# npm info using node#v0.12.0
# npm verb install where, deps [ '/Users/timkelty/tmp/edwards-garment-website', [] ]
# npm verb install where, peers [ '/Users/timkelty/tmp/edwards-garment-website', [] ]
# npm info preinstall edwards-garment-website#1.1.0
# npm info build /Users/timkelty/tmp/edwards-garment-website
# npm verb linkStuff [ false, false, false, '/Users/timkelty/tmp' ]
# npm info linkStuff edwards-garment-website#1.1.0
# npm verb linkBins edwards-garment-website#1.1.0
# npm verb linkMans edwards-garment-website#1.1.0
# npm verb rebuildBundles edwards-garment-website#1.1.0
# npm info install edwards-garment-website#1.1.0
# npm info postinstall edwards-garment-website#1.1.0
# npm verb exit [ 0, true ]
# npm info ok
Running "gulp build" on local.
# [15:14:32] Local gulp not found in ~/tmp/edwards-garment-website
# [15:14:32] Try running: npm install gulp
'build' errored after 755 ms
Error: Command failed: /bin/sh -c gulp build
With sudo:
Running "sudo npm install --verbose" on local.
# npm info it worked if it ends with ok
# npm verb cli [ '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/node',
# npm verb cli '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm',
# npm verb cli 'install',
# npm verb cli '--verbose' ]
# npm info using npm#2.5.1
# npm info using node#v0.12.0
# npm verb install where, deps [ '/Users/timkelty/tmp/edwards-garment-website',
# npm verb install [ 'Select2',
# npm verb install 'autoprefixer-core',
# npm verb install 'babel',
...so for some reason, when running without sudo, the npm install command seems to think it doesn't have any dependencies to install, so it finishes without error and continues to my next task.
I found the solution!
The problem was that I was trying to install devDependencies, but when I ran the gulp deploy command, NODE_ENV was set to production, which does not install devDependencies.
Therefore, changing the command to NODE_ENV=development npm install seems to fix it!
After update #2, I have more options to write why this combination don't work/ First of all, we need to figure out which user a execute the commands. To do this, you need to execute command whoami and see result (you can do it through ssh or shipit task). The direct question is what priveleges don't have user to install packages.
Possible solution #1:
User don't have rights on tmp folder. We can check it via ls -ld /path/to/tmp, expected output:
drwxrwxrwt 13 root root 280 May 8 19:42 /tmp
You need to verify, that all users can write in tmp dir: drwxrwxrwx. If not, you can set by chmod -R 755.
Possible solution #2:
Execute on npm is granted only on owner user/group, and our user don't have ones. We can check it via ls -lL $(which npm). Expected output:
-rwxr-xr-x 1 root root 1881 Apr 19 07:12 /usr/../lib/node_modules/npm/bin/npm-cli.js
If there is no permission x on file, then execute sudo chmod +x $(which npm).
UPDATE:
After this question there is might be also problem not with your tmp folder, but with debug folder for npm. Try to search for one & check permission.
Hope it's all options that we can met.

npm hangs while trying to install gulp

UPDATED:
When I try to install any package with 'npm install', or any variant:
npm install gulp -g -verbose
npm install gulp -verbose
npm install gulp
npm install
npm install connect
I get the following output but it just hangs on the last line, never finishing the install:
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'install',
npm verb cli 'gulp',
npm verb cli '-g',
npm verb cli '-verbose' ]
npm info using npm#2.5.1
npm info using node#v0.12.0
npm verb node symlink C:\Program Files\nodejs\\node.exe
npm verb cache add spec gulp
npm verb addNamed gulp#*
npm verb addNameRange registry:https://registry.npmjs.org/gulp not in flight; fetching
npm verb request uri https://registry.npmjs.org/gulp
npm verb request no auth needed
npm info attempt registry request try #1 at 4:09:05 PM
npm verb request id 77dfc5813704dba8
npm verb etag "EOZJDNUCAN683DXC55T2W1JVT"
npm http request GET https://registry.npmjs.org/gulp
npm http 304 https://registry.npmjs.org/gulp
npm verb etag https://registry.npmjs.org/gulp from cache
npm verb get saving gulp to C:\Users\iwiegand.TMI\AppData\Roaming\npm-cache\registry.npmjs.org\gulp\
.cache.json
npm verb addNamed gulp#3.8.11
npm verb addRemoteTarball https://registry.npmjs.org/gulp/-/gulp-3.8.11.tgz not in flight; adding
npm verb addRemoteTarball [ 'https://registry.npmjs.org/gulp/-/gulp-3.8.11.tgz',
npm verb addRemoteTarball 'd557e0a7283eb4136491969b0497767972f1d28a' ]
^CTerminate batch job (Y/N)?
It's definitely not https, since changing it to http yields the same result. It does this from any folder on my machine, no matter what package, or even just 'npm install'. I've restarted, resintalled node.js, etc. I'm on a Windows 8.1 machine and wishing I had a Mac.
The crazy thing is it HAS worked. I got Composer, Laravel and a bunch of other stuff installed just fine, then one day, it just started doing this. I have no idea what could be interfering. Checking the TaskManager, npm IS running with like 18% CPU usage the whole time it's "trying" to install.
Apparently I'm the only one on Earth with this problem. I've searched and searched on Google and nothing. I'm resorting to Facebook and Google groups. So far no suggestions from SO users have helped, although I very much appreciate the attempts.
I recently came across this problem and managed to fix it, on my own machine at least, by correcting my TEMP environment variable that had been mucked with by some other installer or npm package. I found an issue on github that was describing the exact same problem and I posted my discovery and resolution there.
Basically, someone had appended ;C:\Python27 to the end of my TEMP which was screwing up the unpacking of the npm module. So, maybe it's a long shot, but check it out and see if it works for you!

npm install error ENOTDIR

I am very new to Node.js and trying to install Flatiron using npm but it gives me an error.
sudo npm install flatiron -g
And I get -
npm http GET https://registry.npmjs.org/flatiron
npm http 304 https://registry.npmjs.org/flatiron
npm ERR! Error: ENOTDIR, mkdir '/home/siddharthsaha/tmp/npm-28554/1353323290836-0.20847953506745398'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.2.0-24-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "flatiron" "-g"
npm ERR! cwd /home/siddharthsaha/denarit
npm ERR! node -v v0.8.14
npm ERR! npm -v 1.1.65
npm ERR! path /home/siddharthsaha/tmp/npm-28554/1353323290836-0.20847953506745398
npm ERR! code ENOTDIR
npm ERR! errno 27
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/siddharthsaha/denarit/npm-debug.log
npm ERR! not ok code 0
What is wrong here? I have no clue.
Just solved the issue. Its because there's a file called tmp in the home directory.
rm -rf ~/tmp
sudo npm cache clear
sudo npm install -g node
Also... if you are trying to install npm then the same error and solution applies - delete ~/tmp
Try
sudo mkdir -p /home/siddharthsaha/tmp
sudo npm cache clear
before starting the install script, since npm http 304 https://registry.npmjs.org/flatiron line states that this module is coming from cache. And also ENOTDIR states that there is no directory. Therefore, emptying the cache would solve your problem.
Below are the steps to install a given release from source without root
NOTE - this installs nodejs which gives you both node as well as npm,
they come together per release.
to start fresh remove prior node.js and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
to install nodejs and npm as yourself NOT root do these commands (OSX/linux) :
export NODE_PARENT=${HOME}/bin_0_10_32
mkdir ${NODE_PARENT}
download source from : http://nodejs.org/download/
cd node-v0.xxxx
./configure --prefix=${NODE_PARENT}/nodejs
make -j8
make install # IMPORTANT this is NOT using sudo
# not wanted since installing into $USER owned $NODE_PARENT
which puts it into dir defined by above --prefix
export PATH=${NODE_PARENT}/nodejs/bin:$PATH
define environment variable NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into current dir :
export NODE_PATH=${NODE_PARENT}/nodejs/lib/node_modules
when you use syntax : npm install -g some_cool_module
the -g for global installs it into dir $NODE_PATH and not your $PWD
nodejs install gives you npm as well :
ls -la ${NODE_PARENT}/nodejs/bin
Subsequent modules you install using global flag -g will automagically put
their ~binaries~ into above bin dir ... like browserify
Now put above three export xxx=yyy
commands into your ~/.bashrc or some such so your environment is setup
I direct delete the file of npm-debug.log.
then it's ok for me.

Resources