【问题标题】:NPM removes required dependency when installing new dependencyNPM 在安装新依赖项时删除所需的依赖项
【发布时间】:2018-07-09 09:26:09
【问题描述】:

我的机器经常出现奇怪的问题。每次我安装一些新的 npm 依赖项时,gulp 都会神奇地从 node_modules 文件夹中消失。

gulp 目前作为 devDependency 安装为:"gulp": "github:gulpjs/gulp"

如果我发出通常的npm install 一切都会恢复正常

非常清楚:

$ npm install github:gulpjs/gulp --save-dev
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

+ gulp@4.0.0
added 183 packages in 26.452s

然后如果我尝试安装新的东西...

$ npm install eyeglass --verbose
npm info it worked if it ends with ok
npm verb cli [ '/Users/peach/.nvm/versions/node/v8.11.3/bin/node',
npm verb cli   '/Users/peach/.nvm/versions/node/v8.11.3/bin/npm',
npm verb cli   'install',
npm verb cli   'eyeglass',
npm verb cli   '--verbose' ]
npm info using npm@5.6.0
npm info using node@v8.11.3
npm verb npm-session 48e35d62250ec820
npm http fetch GET 200 https://registry.npmjs.org/eyeglass 15ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/ensure-symlink 20ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/archy 22ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/deasync 21ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/lodash.includes 20ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/fs-extra 21ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/lodash.merge 24ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/node-sass-utils 25ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/bindings 3ms (from cache)
npm verb correctMkdir /Users/peach/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /Users/peach/.npm/_locks/staging-89e2cc30db562072.lock for /Users/peach/repos/sotb-six/node_modules/.staging
npm info lifecycle gulp@4.0.0~preuninstall: gulp@4.0.0
npm info lifecycle gulp@4.0.0~uninstall: gulp@4.0.0
npm verb unbuild rmStuff gulp@4.0.0 from /Users/peach/repos/sotb-six/node_modules
npm info lifecycle gulp@4.0.0~postuninstall: gulp@4.0.0
...

+ eyeglass@1.5.0
removed 183 packages and updated 1 package in 10.707s
npm verb exit [ 0, true ]
npm info ok

接下来是很多其他的包删除...

不知道发生了什么,我很不幸试图为此找到解决方案

使用npm@5.6.0node@v8.11.3

[edit] 尝试删除 package-lock.json 并重新安装 gulp,然后分别安装 $whateverpackage,但结果相同。

$ rm package-lock.json
$ npm install github:gulpjs/gulp
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

+ gulp@4.0.0
added 183 packages in 32.953s
$ ls -l node_modules/.bin/gulp
lrwxr-xr-x 1 peach staff 19 Jul  9 13:24 node_modules/.bin/gulp -> ../gulp/bin/gulp.js
$ npm install eyeglass
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

+ eyeglass@1.5.0
removed 183 packages and updated 1 package in 12.959s
$ ls -l node_modules/.bin/gulp
ls: cannot access 'node_modules/.bin/gulp': No such file or directory

【问题讨论】:

  • node_modules/gulp 还在吗?
  • 不。它被完全卸载了。 (它是被删除的 183 个软件包的一部分)
  • 到目前为止我发现: • 使用 npm 6.1 而不是 5.6 时有效 • 使用 npm install eyeglass --save 时有效 • 使用 npm install eyeglass --no-dev 时有效 您能确认这些发现吗?跨度>
  • @RaphaelSchweikert 可以确认,npm 5* 将被删除,6 保持 gulp,无论选项如何(不带选项运行并且按预期工作)。
  • 是的,npm 6 可以正常工作,但对我来说,5.6 也可以(至少有时)使用这些选项。

标签: node.js npm gulp npm-install


【解决方案1】:

这是由于 npm 中的错误:https://github.com/npm/npm/issues/19394

升级到 npm >= 5.7.0 将解决此问题。

【讨论】:

    猜你喜欢
    • 2020-05-13
    • 2020-05-12
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 2016-08-21
    • 2020-12-28
    • 2018-01-17
    • 2016-08-02
    相关资源
    最近更新 更多