更新时间:2022-05-10 22:54:38
有几种方法可以解决这个问题:
There are several ways to deal with this:
忽略它.只是一个警告,不影响模块的安装.
Ignore it. It's just a warning and does not affect the installation of modules.
运行 npm ci
确保您的 node_modules
反映锁定文件,然后删除 package-lock.json
,然后运行 npm install
(使用较新版本npm
) 来重新生成一个 package-lock.json
.因为 node_modules
中的所有内容都将满足所有要求,所以 npm install
的唯一变化将是新生成的 package-lock.json
文件.将 package-lock.json
的更新版本提交到 repo/Docker 映像或其他任何内容.
Run npm ci
to make sure your node_modules
reflects the lock file, then remove package-lock.json
, and then run npm install
(with the newer version of npm
) to regenerate a package-lock.json
. Because everything in node_modules
will meet all the requirements, the only change from npm install
will be a newly-generated package-lock.json
file. Commit the updated version of package-lock.json
to the repo/Docker image or whatever.
将 npm
降级到生产中的旧版本.考虑运行 npm
版本 6,因为这是当前(在撰写本文时)长期支持 (LTS) 版本的 Node.js 附带的.在这个问题中被问到的情况下,我想你可以从 Dockerfile 中省略 RUN npm -g install npm@7.19.1
而使用 npm
的版本随 Docker 映像一起安装的 code>(在这种情况下几乎可以肯定是 npm@6
,因为这是 Node.js 14.x 附带的).
Downgrade npm
to an older version in production. Consider running npm
version 6 as that is what ships with the current (as of this writing) Long Term Support (LTS) version of Node.js. In the case being asked about in this question, I imagine you can just leave out the RUN npm -g install npm@7.19.1
from the Dockerfile and instead use the version of npm
that is installed with the Docker image (which in this case will almost certainly be npm@6
since that is what ships with Node.js 14.x).
如果你已经安装了一个版本的 npm
,但是想用旧版本的 npm
运行一个命令,但要保留新版本,你可以使用 npx
(随 npm
提供)来做到这一点.使用 -p
标志指定您想要的 npm
版本.例如,即使您安装了版本 7,npx -p npm@6 npm ci
也会使用 npm
版本 6 运行 npm ci
.p>
If you already have a version of npm
installed but want to run one command with an older version of npm
but otherwise keep the newer version, you can use npx
(which ships with npm
) to do that. Use the -p
flag to specify the version of npm
you want. For example, npx -p npm@6 npm ci
would run npm ci
with npm
version 6 even if you have version 7 installed.