使用Yeoman设置AngularJS项目后,“npm install”出现问题

4

当使用以下命令创建Angular项目后(甚至在创建期间),我的问题就出现了:

yo angular

在安装package.json中所有devDependencies(即angular运行的“npm install”)的过程中,我注意到node_modules文件夹中缺少一些模块。因此,之后我用“npm install name_of_the_module --save-dev”重新下载(这样它们就会被下载并包含在package.json的devDependencies选项中)。但是,例如,如果我删除node_modules文件夹并执行命令npm install,则会启动安装过程,但会错过一些模块,有时缺少的模块与上次运行npm install不同。我不知道该如何解决这个问题,因为我需要为团队设置项目,并且他们首先要做的事情是执行“npm install&bower install”(这个最后一个可以运行正常)。package.json的内容如下:
{
  "name": "angular_test",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-autoprefixer": "^0.7.6",
    "grunt-concurrent": "^0.5.0",
    "grunt-contrib-clean": "^0.5.0",
    "grunt-contrib-concat": "^0.4.0",
    "grunt-contrib-connect": "^0.7.1",
    "grunt-contrib-copy": "^0.5.0",
    "grunt-contrib-cssmin": "^0.9.0",
    "grunt-contrib-htmlmin": "^0.3.0",
    "grunt-contrib-imagemin": "^0.8.1",
    "grunt-contrib-jshint": "^0.10.0",
    "grunt-contrib-uglify": "^0.4.1",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-filerev": "^0.2.1",
    "grunt-google-cdn": "^0.4.0",
    "grunt-karma": "^0.9.0",
    "grunt-newer": "^0.7.0",
    "grunt-ng-annotate": "^0.3.2",
    "grunt-svgmin": "^0.4.0",
    "grunt-usemin": "^2.4.0",
    "grunt-wiredep": "^1.7.0",
    "imagemin-jpegtran": "^2.0.0",
    "imagemin-pngquant": "^2.0.0",
    "jshint-stylish": "^0.2.0",
    "karma": "^0.12.24",
    "karma-jasmine": "^0.1.5",
    "karma-phantomjs-launcher": "^0.1.4",
    "load-grunt-tasks": "^0.6.0",
    "time-grunt": "^0.3.2"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

执行npm install后我得到的错误或日志如下:
npm WARN optional dep failed, continuing imagemin-optipng@1.0.0
npm WARN optional dep failed, continuing http-signature@0.10.0
npm WARN optional dep failed, continuing imagemin-jpegtran@1.0.0
npm WARN optional dep failed, continuing imagemin-pngquant@1.0.2
npm WARN optional dep failed, continuing imagemin-gifsicle@1.0.0
npm ERR! EEXIST, open 'C:\Users\myself\AppData\Roaming\npm-cache\78af9c6a-m-cache-lodash-2-4-1-package-tgz.lock'
File exists: C:\Users\myself\AppData\Roaming\npm-cache\78af9c6a-m-cache-lodash-2-4-1-package-tgz.lock
Move it away, and try again.

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\Users\myself\Documents\PHPStorm_Workspace\angular_test
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! path C:\Users\myself\AppData\Roaming\npm-cache\78af9c6a-m-cache-lodash-2-4-1-package-tgz.lock
npm ERR! code EEXIST
npm ERR! errno 47
npm ERR! not ok code 0

更新

所有这些问题都是由于“npm”引起的,所以经过一番研究,npm的创建者建议下载最新版本,只有以下两种方法可用:

npm install -g npm@next

或者

npm install -g npm@2.1.2(在这种情况下,仅适用于当前发布的2.1.2版本,这是最新版本)

或者

当我找到github讨论时,我会更新此帖子。


以下是在Windows中修复此问题的详细说明:https://dev59.com/WoTba4cB1Zd3GeqP2S_h#26547749 - dbasch
3个回答

2

1

文件已存在: C:\Users\myself\AppData\Roaming\npm-cache\78af9c6a-m-cache-lodash-2-4-1-package-tgz.lock 移动它并重试。

看起来npm正在从缓存中解析,尝试# npm cache clear(了解更多信息)以确保包没有从npm的缓存中加载任何内容。


1
我尝试了几次,但即使清除缓存并再次运行“npm install”,该消息仍然会出现。 - Joe Lewis
嗯,只是好奇地尝试将你的 package.json 依赖项更改为 2.4.0,然后再进行另一个 npm 安装。 - pedrommuller
我应该将哪个依赖项更改为2.4.0? - Joe Lewis
看起来你在使用 imagemin-optipng@1.0.0 时遇到了问题,如果不是这个问题,请找到第一个无法解析的依赖项并尝试将其降级一个次要版本,看看情况如何。 - pedrommuller

1

很可能是由于npm中的this bug导致的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接