npm错误!semver.simplifyRange不是函数
尝试遵循Express入门教程。
我生成了一个应用程序并npm install按照提供的说明运行。
> npx express-generator --view=pug myapp
> npm install
npm ERR! semver.simplifyRange is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2021-03-21T04_58_39_577Z-debug.log
日志中的相关部分
555 http fetch GET 200 https://registry.npmjs.org/longest/-/longest-1.0.1.tgz 706ms
556 timing reifyNode:node_modules/longest Completed in 751ms
557 timing metavuln:cache:get:security-advisory:transformers:qlM2fO34VL+rWNeim/6QsbBJFfHtRf4Z7FAoL1JLqVXlvg5FMRxw1WstcKR09WDDJCiJsPPrdRJugEOTZ6eGZA== Completed in 22ms
558 verbose stack TypeError: semver.simplifyRange is not a function
558 verbose stack at Advisory.[calculateRange] (/usr/lib/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/advisory.js:191:16)
558 verbose stack at Advisory.load (/usr/lib/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/advisory.js:148:28)
558 verbose stack at Calculator.[calculate] (/usr/lib/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/index.js:59:14)
558 verbose stack at async Promise.all (index 0)
558 verbose stack at async Map.[init] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/audit-report.js:177:7)
558 verbose stack at async Map.run (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/audit-report.js:105:7)
节点的新手,我不知道这意味着什么。看起来是 npm 而不是 Express 的问题?
我尝试运行npm cache clean --force和删除,node_modules但都没有帮助。
如果相关,请使用 npm 版本 7.6.3 和节点版本 15.11.0。
回答
我的解决方案是安装旧版本的 semver 并将 npm 本身更新到版本 7.7.0。我使用了以下命令:
sudo npm install -g semver@7.2.0
进而
sudo npm install -g npm@7.7.0
工作后