Javascript /npm安装路径错误

javascript/npm install path resolved incorrectly

本文关键字:路径 错误 安装 npm Javascript      更新时间:2023-09-26

我在一个JS项目上开始我的工作,在那里我想使用bower, grunt等。qunit-sinon是我项目的主目录:

tducin@home:~/Development/qunit-sinon (grunt)$ ll
razem 192
drwxrwxr-x 5 tducin tducin   4096 sie 24 11:45 ./
drwxrwxr-x 3 tducin tducin   4096 sie 23 18:00 ../
drwxrwxr-x 5 tducin tducin   4096 sie 23 18:18 bower_components/
-rw-rw-r-- 1 tducin tducin    458 sie 23 18:15 bower.json
drwxrwxr-x 8 tducin tducin   4096 sie 24 11:42 .git/
-rw-rw-r-- 1 tducin tducin    552 sie 23 20:46 .gitignore
-rw-rw-r-- 1 tducin tducin   1148 sie 24 11:41 Gruntfile.js
-rw-rw-r-- 1 tducin tducin    485 sie 23 18:26 index.html
-rw-rw-r-- 1 tducin tducin   1079 sie 23 20:45 LICENSE
drwxrwxr-x 4 tducin tducin   4096 sie 24 11:46 node_modules/
-rw-rw-r-- 1 tducin tducin 140356 sie 24 11:45 npm-debug.log
-rw-rw-r-- 1 tducin tducin    346 sie 24 11:44 package.json
-rw-rw-r-- 1 tducin tducin    324 sie 23 18:30 README.md
-rw-rw-r-- 1 tducin tducin   1402 sie 24 11:00 tests.js

我已经安装了以下全局:node/npm, bower, grunt-cli。我用grunt-init gruntfile来初始化Gruntfile.js。我的package.json内容为:

tducin@home:~/Development/qunit-sinon (grunt)$ cat package.json 
{
  "engines": {
    "node": ">= 0.10.0"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/tkoomzaaskz/qunit-sinon"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-qunit": "~0.5.2",
    "grunt-contrib-watch": "~0.6.1"
  }
}

现在我想运行npm install安装所有缺失的模块(少数grunt插件有自动添加到Gruntfile.js),然后我得到以下错误:

tducin@home:~/Development/qunit-sinon (grunt)$ npm install
npm ERR! Error: EACCES, mkdir '/home/tducin/.npm/underscore/1.6.0'
npm ERR!  { [Error: EACCES, mkdir '/home/tducin/.npm/underscore/1.6.0']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/home/tducin/.npm/underscore/1.6.0',
npm ERR!   parent: 'jshint' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.13.0-34-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! cwd /home/tducin/Development/qunit-sinon
npm ERR! node -v v0.10.31
npm ERR! npm -v 1.4.23
npm ERR! path /home/tducin/.npm/underscore/1.6.0
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/tducin/.npm/underscore/1.6.0'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/tducin/Development/qunit-sinon/npm-debug.log
npm ERR! not ok code 0

npm想要全局安装——这就是为什么他想要管理员权限。但这不是我想做的。

我很肯定这个错误的原因是很明显的,然而,我不知道。请解释为什么npm试图安装在/home/tducin/.npm(全局)而不是我的本地项目node_modules目录。

我不能评论,因为rep…

调试日志中有什么吗?/home/tducin/Development/qunit-sinon/npm-debug.log

它看起来不像是试图全局安装,因为全局模块通常在/usr/local/lib/node_modules/usr/lib/node_modules

请张贴结果:

ls -l -a /home/tducin/ | grep npm

由于.npm文件夹可能已经被创建为根目录

好吧,过了一段时间,我遇到了类似的问题。事实上,我是~/.npm目录本身的所有者,而不是根目录的所有者。但我的问题是,~/.npm的一些内容是我的,有些是根的。这就是为什么一些模块安装成功而另一些模块安装失败的原因。这可能是因为我使用npm install的方式不对。

下面的命令修复了这个问题:

sudo chown -R tducin:tducin ~/.npm