如何修复 /usr/lib/node_modules/npm/node_modules 中的 NodeJS / NPM TypeError: Class extends value undefined is not a constructor or null
问题:
当你尝试运行任何 npm 命令如 npm start 时,你看到类似这样的错误消息
error.txt
/usr/lib/node_modules/npm/lib/es6/validate-engines.js:31
throw err
^
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/fs-minipass/lib/index.js:136:4)
at Module._compile (node:internal/modules/cjs/loader:1233:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:119:18)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/cacache/lib/content/read.js:4:13)
at Module._compile (node:internal/modules/cjs/loader:1233:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)解决方案
这是 npm 或 npm 所需包的内部错误。通常由 NodeJS 和 npm 的不完整更新引起,导致 npm 或其依赖项处于损坏状态。
解决方案是重新安装 NodeJS:
- 使用类似以下命令卸载 NodeJS
uninstall_node.sh
sudo apt remove nodejs- 完全删除 NodeJS 包文件夹,在 Linux 上可以移动到备份位置,例如
backup_node_modules.sh
sudo mv /usr/lib/node_modules ~/node_modules_backup- 使用类似以下命令重新安装 NodeJS
install_node.sh
sudo apt -y install nodejs- 重新安装你需要的任何全局安装包,如
npm i -g @angular/cli
Check out similar posts by category:
NodeJS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow