【问题标题】:How to create react app using yarn instead of npm?如何使用纱线而不是 npm 创建反应应用程序?
【发布时间】:2022-03-18 12:00:20
【问题描述】:

react documentation中提到了创建react app的官方方法

我认为 npx create-react-app project 会自动检测 yarn,但在我的情况下它没有,并使用我不想要的 npm 创建反应应用程序。

第二个选项让我使用yarn create react-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.22" 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 > 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".

那么有没有更好的方法来使用 npx(使用 yarn)创建反应应用程序

【问题讨论】:

    标签: reactjs linux ubuntu npm yarnpkg


    【解决方案1】:

    create-react-app 不需要使用 yarn,因为这个 npm 包不是本地开发依赖项。它用于下载 React 项目的模板,react-scripts 包完成了所有“神奇”的工作。

    the official documentation 之所以建议使用npx 是因为它在创建模板后会删除该包。这意味着当您要创建另一个 React 项目时,它将始终使用最新版本的 create-react-app

    【讨论】:

    • 我的意思是说,每当我写 npx create-react-app 时,它会生成带有 package-lock.json 的反应应用程序,但我希望它生成 yarn.lock
    • @SulemanElahi 我想这应该会有所帮助 - stackoverflow.com/a/61938578/8203841
    猜你喜欢
    • 2022-08-22
    • 1970-01-01
    • 2017-11-13
    • 2020-06-04
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2020-12-04
    • 1970-01-01
    相关资源
    最近更新 更多