在 Manjaro 上更新包时无法提交事务(冲突文件)

Failed to commit transaction (conflicting files) when updating packages on Manjaro

sudo pacman -Syu

我尝试在我的 Manjaro 上使用 pacman 更新所有包 Linux 并且 pacman 必须尽一切努力下载所有可用包的最新更新,并在检查文件冲突后抛出

...
(126/126) checking keys in keyring  100%
(126/126) checking package integrity 100%
(126/126) loading package files 100%
(126/126) checking for file conflicts
error: failed to commit transaction (conflicting files)
npm: /usr/lib/node_modules/npm/lib/exec/get-workspace-location-msg.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/@npmcli/git/lib/utils.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/balanced-match/.github/FUNDING.yml exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/just-diff/index.d.ts exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/just-diff/index.tests.ts exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/CHANGELOG.md exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/LICENSE exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/README.md exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/lib/cache-install-dir.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/lib/get-bin-from-manifest.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/lib/manifest-missing.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/lib/no-tty.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/lib/run-script.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/libnpmexec/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/proc-log/LICENSE exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/proc-log/README.md exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/proc-log/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/proc-log/package.json exists in filesystem
Errors occurred, no packages were upgraded.

我是否应该针对 node_modules 做任何特定的事情,我假设是要覆盖全局安装的节点模块或其他什么?

首先删除 npm 包,然后删除 node_modules 目录是我用来完成这项工作的解决方法。但是,我不确定这是否是正确的解决方案。您可以在进行完整更新之前执行类似的操作,然后重新安装 npm。

$ sudo pacman -Rns npm
$ sudo rm -R /usr/lib/node_modules/npm/
$ sudo rm -R /usr/share/man/man1/
$ sudo pacman -Syyu
$ sudo pacman -S npm

只需 sudo rm -fr /usr/lib/node_modules 也可以。 node_modules 是 npm 编译东西的地方,所以只需删除编译内容。

你可以sudo pacman -S npm --overwrite '/usr/lib/node_modules/npm/*'

回答作者的评论:

It basically resolves conflicts by overwriting files. In your case, conflicting files are all located in /usr/lib/node_modules/npm/ therefore the * will match all of them. No need to delete them manually with rm -r which would leave the package in an inconsistent state. It is good practice to update/upgrade afterward with sudo pacman -Syyu.

最好使用这个 ->

pacman -Syu blackarch --overwrite '*'