如何安装 NPM 拒绝安装的依赖项?
Posted
技术标签:
【中文标题】如何安装 NPM 拒绝安装的依赖项?【英文标题】:How do I install dependencies that NPM refuses to install? 【发布时间】:2020-07-04 15:03:54 【问题描述】:在运行 docker build 时,我收到一个错误,缺少 core-js 依赖项。在运行 npm 建议的安装命令时,我收到另一个错误。我试图恢复到以前的几个分支,但没有雪茄。
docker build .
上的错误是:
ERROR Failed to compile with 122 errors5:31:56 AM
These dependencies were not found:
* core-js/modules/es6.array.copy-within in ./src/main.js
* core-js/modules/es6.array.fill in ./src/main.js
* core-js/modules/es6.array.find in ./src/main.js
* core-js/modules/es6.array.find-index in ./src/main.js
* core-js/modules/es6.array.from in ./src/main.js
* core-js/modules/es6.array.iterator in ./src/main.js
* core-js/modules/es6.array.of in ./src/main.js
* core-js/modules/es6.array.sort in ./src/main.js
* core-js/modules/es6.array.species in ./src/main.js
* core-js/modules/es6.date.to-primitive in ./src/main.js
...
加上另外一百行类似的行,然后是这个建议:
To install them, you can run: npm install --save core-js/modules/es6.array.copy-within core-js/modules/es6.array.fill core-js/modules/es6.array.find core-js/modules/es6.array.find-index core-js/modules/es6.array.from core-js/modules/es6.array.iterator core-js/modules/es6.array.of core-js/modules/es6.array.sort core-js/modules/es6.array.species core-js/modules/es6.date.to-primitive core-js/modules/es6.function.has-instance core-js/modules/es6.function.name core-js/modules/es6.map core-js/modules/es6.math.acosh core-js/modules/es6.math.asinh core-js/modules/es6.math.atanh core-js/modules/es6.math.cbrt core-js/modules/es6.math.clz32 core-js/modules/es6.math.cosh core-js/modules/es6.math.expm1 core-js/modules/es6.math.fround core-js/modules/es6.math.hypot core-js/modules/es6.math.imul core-js/modules/es6.math.log10 core-js/modules/es6.math.log1p core-js/modules/es6.math.log2 core-js/modules/es6.math.sign core-js/modules/es6.math.sinh core-js/modules/es6.math.tanh core-js/modules/es6.math.trunc core-js/modules/es6.number.constructor core-js/modules/es6.number.epsilon core-js/modules/es6.number.is-finite core-js/modules/es6.number.is-integer core-js/modules/es6.number.is-nan core-js/modules/es6.number.is-safe-integer core-js/modules/es6.number.max-safe-integer core-js/modules/es6.number.min-safe-integer core-js/modules/es6.number.parse-float core-js/modules/es6.number.parse-int core-js/modules/es6.object.assign core-js/modules/es6.object.freeze core-js/modules/es6.object.get-own-property-descriptor core-js/modules/es6.object.get-own-property-names core-js/modules/es6.object.get-prototype-of core-js/modules/es6.object.is core-js/modules/es6.object.is-extensible core-js/modules/es6.object.is-frozen core-js/modules/es6.object.is-sealed core-js/modules/es6.object.keys core-js/modules/es6.object.prevent-extensions core-js/modules/es6.object.seal core-js/modules/es6.object.set-prototype-of core-js/modules/es6.promise core-js/modules/es6.reflect.apply core-js/modules/es6.reflect.construct core-js/modules/es6.reflect.define-property core-js/modules/es6.reflect.delete-property core-js/modules/es6.reflect.get core-js/modules/es6.reflect.get-own-property-descriptor core-js/modules/es6.reflect.get-prototype-of core-js/modules/es6.reflect.has core-js/modules/es6.reflect.is-extensible core-js/modules/es6.reflect.own-keys core-js/modules/es6.reflect.prevent-extensions core-js/modules/es6.reflect.set core-js/modules/es6.reflect.set-prototype-of core-js/modules/es6.regexp.constructor core-js/modules/es6.regexp.flags core-js/modules/es6.regexp.match core-js/modules/es6.regexp.replace core-js/modules/es6.regexp.search core-js/modules/es6.regexp.split core-js/modules/es6.regexp.to-string core-js/modules/es6.set core-js/modules/es6.string.anchor core-js/modules/es6.string.big core-js/modules/es6.string.blink core-js/modules/es6.string.bold core-js/modules/es6.string.code-point-at core-js/modules/es6.string.ends-with core-js/modules/es6.string.fixed core-js/modules/es6.string.fontcolor core-js/modules/es6.string.fontsize core-js/modules/es6.string.from-code-point core-js/modules/es6.string.includes core-js/modules/es6.string.italics core-js/modules/es6.string.iterator core-js/modules/es6.string.link core-js/modules/es6.string.raw core-js/modules/es6.string.repeat core-js/modules/es6.string.small core-js/modules/es6.string.starts-with core-js/modules/es6.string.strike core-js/modules/es6.string.sub core-js/modules/es6.string.sup core-js/modules/es6.symbol core-js/modules/es6.typed.array-buffer core-js/modules/es6.typed.float32-array core-js/modules/es6.typed.float64-array core-js/modules/es6.typed.int16-array core-js/modules/es6.typed.int32-array core-js/modules/es6.typed.int8-array core-js/modules/es6.typed.uint16-array core-js/modules/es6.typed.uint32-array core-js/modules/es6.typed.uint8-array core-js/modules/es6.typed.uint8-clamped-array core-js/modules/es6.weak-map core-js/modules/es6.weak-set core-js/modules/es7.array.includes core-js/modules/es7.object.define-getter core-js/modules/es7.object.define-setter core-js/modules/es7.object.entries core-js/modules/es7.object.get-own-property-descriptors core-js/modules/es7.object.lookup-getter core-js/modules/es7.object.lookup-setter core-js/modules/es7.object.values core-js/modules/es7.promise.finally core-js/modules/es7.string.pad-end core-js/modules/es7.string.pad-start core-js/modules/es7.symbol.async-iterator core-js/modules/web.dom.iterable
并以:
结尾npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.1.0 build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-03-24T05_31_56_496Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1
我尝试运行 npm 的建议,结果是:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "core-js/modules/es6.array.copy-within" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/orb/.npm/_logs/2020-03-24T05_44_47_462Z-debug.log
我很困惑。我不确定我是如何丢失 core-js 模块的,因为我上次运行构建时(几天前),我没有遇到任何问题。知道这里发生了什么吗?
Dockerfile:
FROM node:lts-alpine as updraft-frontend-build-stage
#install http server
RUN npm install -g http-server
#make app folder in current directory
WORKDIR /app
#copy package.json and package-lock.json
COPY package*.json ./
#install project dependencies
RUN npm install
#copy in project files & folders
COPY . .
#build app with minification
RUN npm run build
# EXPOSE 8080
# CMD ["http-server", "dist"]
#production stage
FROM nginx:stable-alpine as updraft-frontend-production-stage
COPY --from=updraft-frontend-build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
更新:
尝试在没有缓存层的情况下运行 docker build,但也没有运气。
【问题讨论】:
你能把你的 dockerfile 贴在这里吗? 已发布!希望它能解决问题 您似乎没有安装core-js
。 npm i core-js -S -f
应该可以解决这个问题。
刚刚在另一个帖子中找到了这个。谢谢!问题已修复:)
【参考方案1】:
NPM 不会安装丢失的文件,因为它们是 core-js 的一部分。运行
npm i -S core-js@2.5.7
成功了。
如果您有兴趣,此线程有几个替代选项: Module not found: Error: Can't resolve 'core-js/es6'
【讨论】:
以上是关于如何安装 NPM 拒绝安装的依赖项?的主要内容,如果未能解决你的问题,请参考以下文章
如何让 npm 从 GitHub url 安装 typescript 依赖项?
如何将通过 npm 安装的所有依赖项保存到我的 package.json 文件中?