我正在跟随一个TypeScript教程。
不幸的是,这些包已经过时了,我收到了有关漏洞的警告。
我遵循了npm检查并在需要时更新软件包的一堆建议:
npm audit fix
npm audit fix --force
npm update
npm audit
表示仍然存在 24 个漏洞。
但以上命令均无法修复。
npm outdated
不会输出任何结果。
这些有漏洞的包是:
ansi-regex
glob-parent
node-forge
nth-check
postcss
我其实不知道它们为什么会成为我的项目的一部分。
我在package.json
配置中没有它们。
修复这些漏洞的下一步是什么?
以下是我尝试过的。
- 如何修复npm漏洞?,但是没有答案。
- 手动更新
package.json
中的依赖项到更新版本,然后运行npm install
。但是没有效果。 - 根据这里的建议删除
package-lock.json
,然后再次运行npm install
。 - 将
"ansi-regex": "^6.0.1", "glob-parent": "^6.0.2", "node-forge": "^1.3.0", "nth-check": "^2.0.1", "postcss": "^8.4.12"
添加为devDependencies并运行npm install
。 - 按照如何修复NPM漏洞的建议运行
npm i npm@latest
。 - 如何修复npm漏洞?我尝试了两种方法,问题仍然存在,但没有新的建议。
- 当我检查npm审计时,我有5个中等严重性漏洞,但也没有提出任何新的命令。
- 运行
npm update glob-parent --depth 2
只是发现--depth
已被弃用,NPM总是更新任何深度[GitHub]。 - 运行
npm prune
。 - 删除
node_modules
文件夹,然后再次运行npm install
。
package.json
和 npm install
来复现我的最新状态。{
"name": "pacman",
"version": "0.0.1",
"description": "I just follow a tutorial. Nothing of interest.",
"keywords": ["game"],
"license": "MIT",
"author": "someone stupid",
"scripts": {
"build": "parcel build index.html",
"dev": "parcel index.html --open",
"start": "npm run build && npm run dev",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"ansi-regex": "^6.0.1",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"glob-parent": "^6.0.2",
"node-forge": "^1.3.0",
"nth-check": "^2.0.1",
"parcel": "^2.4.0",
"parcel-bundler": "^1.12.5",
"postcss": "^8.4.12",
"prettier": "^2.6.1",
"typescript": "^4.6.3"
},
"dependencies": {
"npm": "^8.5.5"
}
}
在撰写本文时,运行npm版本8.5.5,这应该会给您带来24个漏洞,其中18个是中等级别的,6个是高级别的。
npm audit
重新创建(可能是其中之一)有漏洞的依赖项上的警告。但如果你只是在跟着教程走(或者它们是开发依赖项),那么这些警告真的很重要吗? - jonrsharpenpm init -y && npm i parcel-bundler@1
->24 vulnerabilities (19 moderate, 5 high)
。或者例如在您发布的内容上执行npm ls node-forge
,如上所建议,将显示尽管直接依赖于1.3.0
,但通过parcel-bundler
,您具有对0.10.0
的传递依赖。 - jonrsharpepackage.json
中。parcel
和parcel-bundler
这两个直接依赖是否包含在原始的package.json
中?还是你后来添加的? - Henke