如何让 create-react-app 使用 npm 而不是 yarn?

How to make create-react-app use npm instead of yarn?

我有点急于根据使用纱线的教程创建一个 React 应用程序。现在我要从头开始重新创建应用程序,因为我对 reactstrap 库不满意,我想切换到 react-bootstrap。

我重新安装了节点。但是,当我 运行 创建反应应用程序时,它说使用 "yarn" 而不是 "npm" 如下:

  yarn start
    Starts the development server.

  yarn build
    Bundles the app into static files for production.

  yarn test
    Starts the test runner.

  yarn eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd react-test
  yarn start

我想使用 npm,因为它似乎使用更广泛并且有更多基于它的示例。我是被 yarn 困住了,还是可以继续使用 npm?

你可以

1) 移除yarn.lock, 运行 npm i,

2) 运行 create-react-app app --use-npm

我不知道这是否有帮助。但我遇到了同样的问题并这样做了

npx expo-cli init --npm

并且它是用 npm 安装的

希望这对你或以后的人有所帮助

  1. 安装 create-react-app npm i -g create-react-app --use-npm
  2. 使用 cd 命令转到所需路径
  3. 添加 --use-npm create-react-app my-app-name --use-npm 此命令将创建一个文件夹,其名称与您在当前路径中提到的名称相同。此文件夹包含 React 应用程序启动代码所需的所有必要配置文件

1 ⇢ 如果你已经安装了 create-react-app 然后使用:

create-react-app --use-npm

2 ⇢ 如果您使用的是 npx 命令,则使用:

npx create-react-app --use-npm

3 ⇢ 对于现有的 yarn 应用程序,删除 yarn.lock 文件和 运行:

npm i

npm install