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

Jac*_*ble 35 npm reactjs yarnpkg

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

我已经重新安装了节点。但是,当我运行 create-react-app 时,它说使用“​​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
Run Code Online (Sandbox Code Playgroud)

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

wen*_*jun 82

你可以

1)删除yarn.lock,并运行npm i

或者

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

  • 没有。只要去掉`yarn.lock`就可以了。这应该会消除它的痕迹和任何版本冲突。如果你想安全起见,可以在运行“npm i”之前删除“node_modules”。这反过来将重新安装依赖项并生成“package-lock.json”。 (3认同)

Saj*_*man 11

1 \xe2\x87\xa2 如果已安装,create-react-app则使用:

\n
create-react-app --use-npm\n
Run Code Online (Sandbox Code Playgroud)\n

2 \xe2\x87\xa2 如果您使用npx命令,则使用:

\n
npx create-react-app --use-npm\n
Run Code Online (Sandbox Code Playgroud)\n

3 \xe2\x87\xa2 对于现有yarn应用程序,删除该yarn.lock文件并运行:

\n
npm i\n
Run Code Online (Sandbox Code Playgroud)\n

或者

\n
npm install\n
Run Code Online (Sandbox Code Playgroud)\n