【问题标题】:Yarn errors when trying to create a React app尝试创建 React 应用程序时出现纱线错误
【发布时间】:2019-04-25 14:17:19
【问题描述】:

我尝试使用以下命令创建一个反应应用程序:

create-react-app eth-todo-list-react

这会产生以下错误:

'yarnpkg' is not recognized as an internal or external command,
operable program or batch file.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

'yarnpkg' is not recognized as an internal or external command,
operable program or batch file.
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: spawn yarnpkg ENOENT
    at notFoundError (C:\Users\Aristophanes\node_modules\create-react-app\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\Aristophanes\node_modules\create-react-app\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\Aristophanes\node_modules\create-react-app\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
Emitted 'error' event at:
    at ChildProcess.cp.emit (C:\Users\Aristophanes\node_modules\create-react-app\node_modules\cross-spawn\lib\enoent.js:30:37)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)

它应该说“成功”并初始化一个 git 存储库。但我得到了上面的错误。我已尝试对各种方法进行故障排除,包括更改路径和全局安装纱线,但是当我这样做然后重新尝试再次创建反应应用程序时,我收到此错误:

The directory eth-todo-list-react contains files that could conflict:

  package.json
  yarn.lock

Either try using a new directory name, or remove the files listed above.

如果我删除此文件并尝试再次创建 react 应用程序,我会再次收到第一个错误。

【问题讨论】:

  • 修改PATH后,当前打开的cmd窗口不受影响,需要关闭再重新打开。
  • 关闭和打开 cmd 没有区别。我总是遇到同样的错误。
  • 尝试先使用“npm install yarn -g”安装yarn
  • 已经尝试全局安装yarn,我得到同样的错误。

标签: javascript reactjs yarnpkg


【解决方案1】:

尝试使用npx 命令,

npx create-react-app my-project

如果您使用npx,则不需要像create-react-app 这样全局安装软件包。

都告诉node -vnpm -v

【讨论】:

【解决方案2】:

通过在控制台中输入 create-react-app --version 来获取您的 create-react-app 版本。这为我使用 2.1.5 版成功构建。您可能需要更新您的 create-react-app。 npm uninstall -g create-react-app npm create-react-app eth-todo-list-react 应该使用最新版本的 create-react-app。

【讨论】:

  • 不起作用,我得到相同的第二个冲突文件错误
猜你喜欢
  • 2022-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 2022-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多