【问题标题】:Unable to create a react app using "create-react-app"无法使用“create-react-app”创建反应应用程序
【发布时间】:2019-11-29 04:17:31
【问题描述】:

我已经使用“npm install create-react-app -g”在我的电脑上全局安装了“create-react-app”。几个月来它工作得很好。我之前使用“create-react-app app-name”命令创建了很多 React 应用程序。它完美无缺。直到几天前它突然停止工作并开始出错。我尝试了各种建议但没有运气。因此,经过几天的尝试解决问题后,我提出了这个问题。

我尝试过做以下事情:

1> using the "npm cache clean --force" and then "npm cache verify".
2> I also unabled my antivirus (norton) and then ran the commands.
3> I installed the latest node version
4> I intalled the latest npm version and updated it using the command "npm install npm@latest -g"
5> I followed the instructions on this stackoverflow link https://stackoverflow.com/questions/50189096/installing-create-react-app-gives-npm-err-shasum-check-failed-and-npm-err-unex/50191315#50191315 to change the registry.
And a few other things. But nothing has worked.

我得到的错误如下:

D:\codes\react\maximilianUdemy\project1>create-react-app react-mytest-app

Creating a new React app in D:\codes\react\maximilianUdemy\project1\react-mytest-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! Unexpected end of JSON input while parsing near '...HqQqP7Ky/f49Ar0oPZ\n4'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\vaibh\AppData\Roaming\npm-cache\_logs\2019-07-20T10_24_27_969Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting react-mytest-app/ from D:\codes\react\maximilianUdemy\project1
Done.

以下是C:\Users\vaibh\AppData\Roaming\npm-cache\_logs\2019-07-20T10_24_27_969Z-debug.log 的摘录。由于日志非常大(664 行),我只记录了错误开始显示的时间。

471 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...HqQqP7Ky/f49Ar0oPZ\n4'
471 verbose stack     at JSON.parse (<anonymous>)
471 verbose stack     at parseJson (D:\Program_Files\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
471 verbose stack     at D:\Program_Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50
471 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:85:5)
472 verbose cwd D:\codes\react\maximilianUdemy\project1\react-mytest-app
473 verbose Windows_NT 10.0.17134
474 verbose argv "D:\\Program_Files\\nodejs\\node.exe" "D:\\Program_Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "--save-exact" "--loglevel" "error" "react" "react-dom" "react-scripts"
475 verbose node v12.6.0
476 verbose npm  v6.9.0
477 error Unexpected end of JSON input while parsing near '...HqQqP7Ky/f49Ar0oPZ\n4'
478 verbose exit [ 1, true ]

【问题讨论】:

  • 试试这个npx create-react-app react-mytest-app
  • 尝试使用 npm uninstall -g create-react-app 卸载并重新安装
  • @ravibagul91 我也试过了。它也给出了同样的错误
  • @Sushilzzz 我之前更新了 npm,但它没有用。我按照你说的卸载重装了,还是一样的错误。
  • 尝试删除C:\Users\&lt;yourUser&gt;\AppData\Roaming\npm-cache下的所有内容

标签: reactjs create-react-app


【解决方案1】:

尝试使用npx create-react-app my-app

我认为this link 中的信息也会对您有所帮助。

【讨论】:

  • 问题陈述是什么?你已经尝试过什么?尝试运行上述命令时出现了哪些错误消息?
【解决方案2】:

这个问题是 create-react-app 版本相对于节点版本。

创建新项目

npx create-react-app project_name --template all

Node

create-react-app

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2019-10-15
    • 2020-10-31
    相关资源
    最近更新 更多