如何确定安装特定软件包的原因? 换句话说,什么软件包依赖于这个软件包?
有问题的包裹已经被洗脑了。npm ls在顶层显示了它,但是 package.json 没有包含它。
npm ls
使用 npm ls列出已安装的软件包,并查看给定软件包的依赖关系图,例如:
> npm ls core-js my_module /path/to/my_module> └─┬ pug@2.0.4 └─┬ pug-code-gen@2.0.2 └─┬ constantinople@3.1.2 └─┬ babel-types@6.26.0 └─┬ babel-runtime@6.26.0 └── core-js@2.6.10
如果你找不到 require或 import,试着看看儿童 package.json,看看还有谁需要它。
require
import
package.json
(注意: find需要 Linux/macOS,这在 Windows 上无法工作)
find
find . -name package.json -exec grep -l babelify /dev/null {} \;
./node_modules/browserify-zlib/package.json ./node_modules/cssnext/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/reporter/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/browserify-preprocessor/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/async/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/babel-core/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/babelify/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/getos/node_modules/async/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/object-assign/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/watchify/node_modules/browserify-zlib/package.json ./node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/package.json ./node_modules/eslint/package.json ./node_modules/extract-text-webpack-plugin/node_modules/async/package.json ./node_modules/getos/node_modules/async/package.json ./node_modules/postcss-modules-extract-imports/package.json ./node_modules/postcss-modules-scope/package.json ./node_modules/webpack/node_modules/async/package.json
正如您所提到的,npm ls显示包及其依赖项:
> npm ls leveldown appless@5.0.0 C:\Users\mikem\Code\appless `-- @architect/architect@5.7.0 `-- dynalite@2.2.0 `-- UNMET OPTIONAL DEPENDENCY leveldown@4.0.2
如果 npm ls在顶级显示它,并且它不是顶级 package.json中的依赖项,那么它很可能以前是必需的,现在不再使用。
使用 npm prune删除未使用的包。
npm prune
有一个名为 npm-why的模块,用于确定安装软件包的原因。
npm-why
当然,如果您使用的是 yarn,那么您有一个内置命令 yarn why。
yarn
yarn why
我的俏皮话,基于其他答案: npm ls | grep -C 10 PACKAGE
npm ls | grep -C 10 PACKAGE
将程序包替换为您正在寻找的程序包。这比其他建议更简单、更快捷。贝壳是你的朋友,朋友!
细目/说明
|
grep [...] PACKAGE
-C 10
-C
-B 10 -A 10
npm explain <package name>就是你要找的。它通过显示“ bottom up”视图解释了为什么包在 node _ module 文件夹中。参见文档 给你
npm explain <package name>