[英]NPM: Why is this package installed?
How do I determine why a particular package is installed?如何确定安装特定软件包的原因? In other words, what package(s) depend on this package?
换句话说,什么包依赖于这个包?
The package in question is babelify.有问题的包是 babelify。
npm ls
shows it at the top level, but it is not included in package.json anywhere. npm ls
在顶层显示它,但它没有包含在 package.json 的任何地方。
Use npm ls
to list installed packages and see the dependency graph of a given package eg:使用
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
As you mention, npm ls
shows packages and their dependencies:正如您提到的,
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
If npm ls
shows it at the top level, and it is not a dependency in the top level package.json
, it's likely was previously required and is now no longer used.如果
npm ls
在顶层显示它,并且它不是顶层package.json
的依赖项,则它可能以前是必需的,现在不再使用。
Use npm prune
to remove the unused package .使用
npm prune
删除未使用的包。
If you can't find a require
or import
, try looking at child package.json
s to see who else needs it.如果找不到
require
或import
,请尝试查看子package.json
以查看还有谁需要它。
(Note: find
requires Linux/macOS, this won't work on Windows) (注意:
find
需要 Linux/macOS,这不适用于 Windows)
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
My one-liner, based on other answers: npm ls | grep -C 10 PACKAGE
我的单线,基于其他答案:
npm ls | grep -C 10 PACKAGE
npm ls | grep -C 10 PACKAGE
Replace PACKAGE with the package you're looking for.将 PACKAGE 替换为您要查找的包。 This is simpler and faster than other suggestions.
这比其他建议更简单、更快。 The shell is your friend, friends!
贝壳是你的朋友,朋友们!
Breakdown/Explanation分解/说明
npm ls
- As explained above, this prints the dependency tree representation of your app. npm ls
- 如上所述,这会打印您的应用程序的依赖树表示。|
- The secret sauce of *nix shells. grep [...] PACKAGE
- Search for the string "PACKAGE" (This is actually regex, but that's irrelevant.) grep [...] PACKAGE
- 搜索字符串“PACKAGE”(这实际上是正则表达式,但这无关紧要。)-C 10
- This tells grep to print 10 extra lines around the matching lines. -C 10
- 这告诉 grep 在匹配行周围打印 10 条额外的行。 Without this, grep would only print the lines were PACKAGE was found.-C
doesn't work on your system (less common linux versions), try using -B 10 -A 10
instead.-C
在您的系统上不起作用(不太常见的 linux 版本),请尝试使用-B 10 -A 10
代替。 It's a more verbose way of doing the same thing: "10 lines before, 10 lines after."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.