gpt4 book ai didi

node.js - NPM 在 docker 容器中升级后中断

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:42 25 4
gpt4 key购买 nike

我需要使用 Node v6.10.3 创建一个 docker 容器,但使用最新的 npm(当前为 v5.4.1),以便为本地包使用新的 npm 功能。

这样的安装在我的 Mac 上运行没有任何问题,但是当我尝试使用这样的安装创建 docker 镜像时,更新 npm 后,npm 工具会损坏并抛出一系列有关丢失软件包的错误。

这是 Dockerfile 的示例,我可以用它重现此问题(请注意,我真正的 Dockerfile 更复杂):

FROM ubuntu:xenial

RUN apt-get update
RUN apt-get install -y curl

RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs

RUN npm i -g npm
RUN npm i -g lerna

当构建过程到达 RUN npm i -g lerna 行时,它会抛出一堆错误,例如:

Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

任何其他 npm 脚本都会导致相同的错误。重新安装 npm 依赖的所有软件包对我来说似乎不是一个解决方案。

我还尝试使用 nvm 在容器内安装 Node ,但遇到了相同的错误。

我的docker版本:

Docker version 17.06.2-ce, build cec0b72

这个 Dockerfile 有什么问题,我缺少什么?

最佳答案

我找到了解决此问题的方法,即使用yarn

看起来很奇怪,但确实有效:

FROM ubuntu:xenial

RUN apt-get update
RUN apt-get install -y curl

RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs

RUN npm i -g yarn
RUN npm uninstall npm -g
RUN yarn global add npm
RUN npm i -g lerna

不过,如果有人能够解释为什么原始解决方案不起作用,和/或帮助找到更好的方法来修复它,那就太好了。

关于node.js - NPM 在 docker 容器中升级后中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46113900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com