create-react-app Peer dependency warnings

3ks5zfa0  于 4个月前  发布在  React
关注(0)|答案(8)|浏览(57)

描述bug

进行全新安装后,会出现很多peer依赖警告。

你是否尝试恢复依赖关系?

❯ yarn --version              
1.22.0

你在用户指南中搜索了哪些术语?

peer dependency warning

环境

react-scripts@5.0.0 .

重现步骤

  1. yarn create react-app my-app

预期行为

没有任何警告。

实际行为

warning " > @testing-library/user-event@13.5.0" has unmet peer dependency "@testing-library/dom@>=7.21.4".                                                                                                           
warning "react-scripts > tailwindcss@3.0.16" has unmet peer dependency "autoprefixer@^10.0.2".      
warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-syntax-flow@^7.14.5".
warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-transform-react-jsx@^7.14.9".
warning "react-scripts > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.0" has unmet peer dependency "typescript@>= 2.7".
warning "react-scripts > webpack-dev-server > http-proxy-middleware@2.0.2" has unmet peer dependency "@types/express@^4.17.13".                
warning "react-scripts > eslint-config-react-app > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev |
| >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
r1wp621o

r1wp621o1#

我正在遇到与yarn 1.22.15相同的问题。据我所知,Yarn和NPM在查找对等依赖项方面存在差异,而NPM没有这个问题。但无论如何,我希望react-scripts能够安装所需的对等依赖项,而不是让react-scripts的用户来处理。

xyhw6mcr

xyhw6mcr2#

pnpm 6.31会产生相同的警告:

 WARN  Issues with peer dependencies found
.
├─┬ @testing-library/user-event
│ └── ✕ missing peer @testing-library/dom@>=7.21.4
└─┬ react-scripts
  ├── ✕ missing peer typescript@"^3.2.1 || ^4"
  ├─┬ eslint-config-react-app
  │ ├─┬ @typescript-eslint/eslint-plugin
  │ │ ├── ✕ missing peer typescript@"*"
  │ │ └─┬ @typescript-eslint/type-utils
  │ │   ├── ✕ missing peer typescript@"*"
  │ │   └─┬ @typescript-eslint/utils
  │ │     └─┬ @typescript-eslint/typescript-estree
  │ │       ├── ✕ missing peer typescript@"*"
  │ │       └─┬ tsutils
  │ │         └── ✕ missing peer typescript@">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta"
  │ ├─┬ @typescript-eslint/parser
  │ │ └── ✕ missing peer typescript@"*"
  │ └─┬ eslint-plugin-flowtype
  │   ├── ✕ missing peer @babel/plugin-syntax-flow@^7.14.5
  │   └── ✕ missing peer @babel/plugin-transform-react-jsx@^7.14.9
  ├─┬ react-dev-utils
  │ └─┬ fork-ts-checker-webpack-plugin
  │   └── ✕ missing peer typescript@">= 2.7"
  └─┬ tailwindcss
    └── ✕ missing peer autoprefixer@^10.0.2
Peer dependencies that should be installed:
  @babel/plugin-syntax-flow@^7.14.5              autoprefixer@^10.0.2                           
  @babel/plugin-transform-react-jsx@^7.14.9      typescript@">=3.2.1 <4.0.0 || >=4.0.0 <5.0.0"  
  @testing-library/dom@>=7.21.4
gjmwrych

gjmwrych3#

eslint-plugin-flowtype 能否被标记为 optionalDependency 以供 eslint-config-react-app 使用?我使用 TypeScript 进行类型检查,并希望不会出现关于它的警告。也许其他 "非核心" 依赖项也可以被标记为 optionalDependencies?从技术上讲,与 TypeScript 相关的包可以被视为 "非核心" 并被标记为可选。

zlhcx6iw

zlhcx6iw4#

我正在使用Yarn 3.2.0,并收到以下警告:

➤ YN0002: │ eslint-config-react-app@npm:7.0.0 [07f45] doesn't provide @babel/plugin-syntax-flow (p19435), requested by eslint-plugin-flowtype
➤ YN0002: │ eslint-config-react-app@npm:7.0.0 [07f45] doesn't provide @babel/plugin-transform-react-jsx (p74774), requested by eslint-plugin-flowtype

可以通过在 .yarnrc.yml 中添加以下内容来静音该警告:

packageExtensions:
  # awaiting fix: https://github.com/facebook/create-react-app/issues/11982
  'eslint-plugin-flowtype@*':
    peerDependenciesMeta:
      '@babel/plugin-syntax-flow':
        optional: true
      '@babel/plugin-transform-react-jsx':
        optional: true
7y4bm7vi

7y4bm7vi5#

@lensbart,这是一个出色的解决方法。我使用了PNPM,它也允许这种行为。谢谢!

v9tzhpje

v9tzhpje6#

如果有人能修复这个问题,那就太好了,我们就不需要使用替代方案了。

9gm1akwq

9gm1akwq7#

请注意:pnpm@7现在默认有strict-peer-dependencies: true(pnpm/pnpm#4427),在安装CRA时会出错。

nwwlzxa7

nwwlzxa78#

有人知道它是否已经修复了吗?因为我在我的CRA中仍然遇到这个问题,使用的是node 16.14.2和cra 18.0.1。

相关问题