如何成功升级lodash:升级失败故障排除

问题描述 投票:0回答:2

尝试在 Node.js 目录中升级 lodash 时,遇到以下错误:

错误1:

sudo npm install lodash@latest
npm WARN saveError ENOENT: no such file or directory, open '/usr/share/nodejs/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/usr/share/nodejs/package.json'
npm WARN nodejs No description
npm WARN nodejs No repository field.
npm WARN nodejs No README data
npm WARN nodejs No license field.

+ [email protected]
updated 1 package and audited 1 package in 0.384s
found 0 vulnerabilities

错误2:

/usr/share/nodejs/lodash$ sudo npm install lodash@latest
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "lodash" under a package
npm ERR! also called "lodash". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-20T03_12_36_652Z-debug.log

当我在其他目录中运行升级命令时,我还注意到 lodash 被安装在 /home/ubuntu/node_modules/ 目录中。但是,我不确定是否需要更新 /usr/share/nodejs 目录中的 lodash,因为它是我使用 npm list lodash 时唯一显示版本信息的目录。另外,我没有在node_modules目录中安装lodash,我不知道如何处理它。

此外,nodejs目录下还有很多lodash相关的文件。这些文件的作用是什么,都和lodash有关吗?”

javascript node.js ubuntu npm lodash
2个回答
0
投票

我认为您在全球范围内安装了软件包。 尝试一次:

npm update -g <package_name>


0
投票

我的 package.json 文件和 lodash 版本

要更新 lodash 版本,只需使用命令

npm install lodash@<lodash_version>

例如:

npm install [email protected]

使用此命令后轻松更新lodash版本

© www.soinside.com 2019 - 2024. All rights reserved.