【问题标题】:Issue with "npm install" after setting up AngularJS project with Yeoman使用 Yeoman 设置 AngularJS 项目后出现“npm install”问题
【发布时间】:2014-11-26 13:12:14
【问题描述】:

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

yo angular

在从 package.json 安装所有 devDependencies 的过程中(你有角度运行的“npm install”)我注意到 node_modules 文件夹中缺少一些模块。

所以,之后我再次下载了“npm install name_of_the_module --save-dev”(因此它们将下载并包含在 devDependencies 选项的 package.json 中)。

但是例如,如果我删除 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 讨论时,我会用它更新帖子。

【问题讨论】:

标签: node.js angularjs gruntjs npm yeoman


【解决方案1】:

这是一个错误,可以通过更新您的 npm 版本 (https://github.com/npm/npm/issues/6318) 来修复。 试试:npm -g install npm@next

【讨论】:

    【解决方案2】:

    文件存在: C:\Users\myself\AppData\Roaming\npm-cache\78af9c6a-m-cache-lodash-2-4-1-package-tgz.lock 将其移开,然后重试。

    似乎 npm 正在从您的缓存中解析,请尝试 # npm cache clear(更多信息 info)以确保包没有从 npm 的缓存中加载任何内容。

    【讨论】:

    • 我尝试了几次,但即使在清理缓存并再次重新运行“npm install”后也会出现该消息
    • mmm 只是好奇尝试将您的 package.json 依赖项更改为 2.4.0 并执行另一个 npm install
    • 我应该将哪个依赖项更改为 2.4.0?
    • 您似乎对 imagemin-optipng@1.0.0 有问题,如果这不是问题,请找到它没有解决的第一个依赖项并尝试降级一个次要版本,看看情况如何跨度>
    【解决方案3】:

    很可能是由于 npm 中的this bug

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 2021-07-10
      • 2014-09-14
      • 2016-10-26
      • 1970-01-01
      • 2021-09-09
      • 2022-07-13
      相关资源
      最近更新 更多