npm - 如何使用 "yarn"或 "npm"列出特定类型的依赖项

标签 npm command-line-interface yarnpkg

在开发包时,我们需要一种方法来知道包“x”是否存在于peerdev 依赖项中,我正在尝试

npm ls --omit dev # to list peers deps

尝试过

yarn list --dev # to list dev deps

我没有成功。

有人可以使用简单的 npmyarn 命令帮助解决这个问题吗?

最佳答案

我相信您的项目文件在您添加它们时未配置/缺少依赖项。无论如何,这有两个步骤,创建依赖项,然后;将其移动到下面列出的 peerDependencies

也请分享您的项目文件以备将来提问

First you need to create those dependencies in your project (explained below #2)

Second/Then NPM/Yarn can leverage that and give the correct results when you list.


第 1 步:如何创建这些依赖项

npm i @angular/core

  • 这将在您的项目文件中添加一个属性

"dependencies": {
    "@angular/core": "^12.0.0"
}

  • 现在,安装后,将安装的包名称移动到 peerDependencies 部分。
"peerDependencies": {
    "@angular/core": "^12.0.0"
}

第 2 步:如何列出对等依赖,请替换 react-native 为您的包

// for peer dependencies on a package & specific release
npm info react-native@latest peerDependencies

// for peer dependencies on a package *** replace react-native with your package
npm info react-native peerDependencies

// for production dependencies 
npm list -dev -depth 0

// or with flags
npm list -depth 0 -prod true

关于npm - 如何使用 "yarn"或 "npm"列出特定类型的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69640673/

相关文章:

node.js - 如何正确使用 package.json 中的 "keywords"属性?

node.js - 请求错误 : getaddrinfo ENOTFOUND github. com

javascript - NPM 安装 jquery 出现错误?定义未定义?

http - 代理后面的 npm 失败,状态为 403

node.js - 在本地安装时如何让我的 NPM 包显示 "npm WARN prefer global"

node.js - 使用 npm/nodejs 命令行实用程序保留用户首选项的最佳方法

php - 使用 php-cli 时出现 pg_connect 错误

mongodb - AWS CLI 的细微差别

yarnpkg - 如何在我的 nix shell 中同步 Node 和 Yarn 版本?

reactjs - 'docker-compose run app yarn add raven-js'未在npm_modules中安装软件包