问题描述
在本地,我已经通过以下方式成功安装了npm @ 5:
Locally, I have successfully installed npm@5 via:
$ npm install npm@5 -g
$ npm -v
$ 5.0.0
在本地,我可以运行npm设置很好(基本上是 npm i&&tsc
)
And locally, I can run the npm setup just fine (it's basically npm i && tsc
)
$ npm run setup
updated 102 packages in 3.499s
现在我也有一个Dockerfile基于 node:7.10-alpine
映像,如果我尝试在其中安装 npm @ 5
,该映像将中断。
Yet now I also have a Dockerfile based upon the node:7.10-alpine
image which breaks if I try to install npm@5
there.
我的Dockerfile看起来像这样:
My Dockerfile looks like this:
FROM node:7.10-alpine
WORKDIR /usr/hive-updater/
ENV LAST_UPDATED=2016-12-08 NPM_CONFIG_LOGLEVEL=warn TERM=xterm PATH="$PATH:/usr/hive-updater/node_modules/.bin"
RUN npm install npm@5 -g && npm -v
COPY ./ ./
RUN npm run setup
CMD ["node"]
这将在 npm -v
期间失败,并带有:
This will fail during npm -v
with:
module.js:472
throw err;
^
Error: Cannot find module 'semver'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
如何获取最新的npm我的docker容器?
How to get the latest npm on my docker container?
推荐答案
我发现。
是Facebook的npm替代品您可以使用它全局安装npm @ 5:
Yarn is Facebook's npm replacement and you can use it to globally install npm@5:
RUN npm -v
RUN yarn global add npm@5
RUN npm -v
COPY ./ ./
RUN npm run setup
(版本调用是多余的,仅强调升级有效。)
(The version calls are superfluous and only to highlight that the upgrade works.)
现在它可以工作了:
Step 4/9 : RUN npm -v
---> Running in dca435fbec59
4.2.0
---> f6635e6c92a3
Removing intermediate container dca435fbec59
Step 5/9 : RUN yarn global add npm@5
---> Running in fac7216ccd91
yarn global v0.24.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "npm@5.0.0" with binaries:
- npm
Done in 10.47s.
---> b6b2e0f3fc36
Removing intermediate container fac7216ccd91
Step 6/9 : RUN npm -v
---> Running in 38a9ee95b9f0
5.0.0
---> d1632fc97b7e
Removing intermediate container 38a9ee95b9f0
Step 7/9 : COPY ./ ./
---> b9b62f53ca48
Removing intermediate container e9dd065c022f
Step 8/9 : RUN npm run setup
---> Running in aec36af706d4
> hive-updater@1.0.0 setup /usr/hive-updater
> npm install --quiet && npm run build
added 102 packages in 5.156s
> hive-updater@1.0.0 build /usr/hive-updater
> tsc
因此,如果npm版本低于5,并且升级方法不适合您,请安装yarn进行升级npm ¯\_(ツ)_ /¯
So if you have npm below version 5 and its upgrade method breaks for you, install yarn to upgrade npm ¯\_(ツ)_/¯
侧注:
最好只使用yarn而不是npm @ 5。仍然具有强大的性能优势。
It might be better to just use yarn instead of npm@5. It still has a strong performance advantage.
比较这些运行,都将其缓存:
Compare these runs, both cached:
yarn install v0.24.5
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.31s.
和npm @ 5:
npm install
updated 102 packages in 3.069s
I不知道纱线
已经随高山图像一起运送了。
I didn't know that yarn
was already shipped with the alpine image.
这篇关于如何在最新的节点docker映像上将npm升级到npm @ 5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!