34

我正在尝试使用 npx create-react 应用程序,但出现如下所示的错误:

npm ERR! Unexpected end of Json input while parsing near
'...eact-app/-/create-rea'

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\dp\AppData\Roaming\npm-cache\_logs\2018-12-06T18-42-56-293Z-debug.log

Install for create-react-app@latest failed with code 1** 

并且错误的日志文件在这里...!

我怎样才能摆脱这个麻烦?

0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',

1 verbose cli   
'C:\\Users\\dp\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',

1 verbose cli   'install',

1 verbose cli   'create-react-app@latest',

1 verbose cli   '--global',

1 verbose cli   '--prefix',

1 verbose cli  
'C:\\Users\\dp\\AppData\\Roaming\\npm-cache\\_npx\\3588',

1 verbose cli   '--loglevel',

1 verbose cli   'error',

1 verbose cli   '--json' ]

2 info using npm@6.4.1

3 info using node@v10.13.0

4 verbose npm-session 7862701600d4f4ce

5 silly install loadCurrentTree

6 silly install readGlobalPackageData

7 http fetch GET 304 

https://registry.npmjs.org/create-react-app 872ms (from cache)

8 silly fetchPackageMetaData error for create-react-app@latest
Unexpected end of JSON input while parsing near
'...eact-app/-/create-rea'

9 timing stage:rollbackFailedOptional Completed in 4ms 10 timing
stage:runTopLevelLifecycles Completed in 1693ms 11 verbose stack
SyntaxError: Unexpected end of JSON input while parsing near
'...eact-app/-/create-rea' 11 verbose stack     at JSON.parse
(<anonymous>) 11 verbose stack     at parseJson
(C:\Users\dp\AppData\Roaming\npm\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
11 verbose stack     at consumeBody.call.then.buffer
(C:\Users\dp\AppData\Roaming\npm\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50)
11 verbose stack     at process._tickCallback
(internal/process/next_tick.js:68:7) 12 verbose cwd C:\Users\dp 13
verbose Windows_NT 6.3.9600 14 verbose argv "C:\\Program
Files\\nodejs\\node.exe"
"C:\\Users\\dp\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js"
"install" "create-react-app@latest" "--global" "--prefix"
"C:\\Users\\dp\\AppData\\Roaming\\npm-cache\\_npx\\3588" "--loglevel"
"error" "--json" 15 verbose node v10.13.0 16 verbose npm  v6.4.1 17
error Unexpected end of JSON input while parsing near
'...eact-app/-/create-rea' 18 verbose exit [ 1, true ]
4

22 回答 22

106

要解决此问题,请按顺序运行这些命令

npm init
npm install create-react-app
npx create-react-app myapp
于 2019-05-24T18:35:57.393 回答
29

我有同样的问题“安装 create-react-app@latest 失败,代码 7”使用这个。它对我有用。

npm install -g create-react-app    
npx create-react-app my-app     
cd my-app      
npm start     

如需进一步参考,请访问:https ://www.techomoro.com/how-to-install-and-setup-a-react-app-on-windows-10/

于 2020-02-10T20:02:19.170 回答
23

清理 npm 缓存:

npm cache clean --force

然后再试一次

于 2019-06-20T17:59:08.003 回答
12

首先,通过在终端中键入以下内容来清除缓存:

npm cache clean --force

然后按照以下步骤或键入来升级您的 npm 版本:

npm install -g npm@next

现在转到Windows 设置中的程序和功能中的“NodeJS”并修复您的安装。

重启终端并输入:

npx create-react-app my-app

这应该有望解决您的问题。

于 2020-06-04T17:19:37.653 回答
7

当我使用来自官方来源https://reactjs.org/docs/create-a-new-react-app.html#create-react-app的命令时,我在创建反应项目时遇到了同样的问题

npx create-react-app my-app
cd my-app
npm start

上面的命令在我的 Windows 上不起作用。我的机器上有 Node >= 6 和 npm >= 5.2 即使它无法打开 localhost:3000 然后我使用了这个命令

npm install -g create-react-app
create-react-app my-app-name
cd my-app-name
npm start

它工作得很好。我从https://www.youtube.com/watch?v=pCgDRgmfileE学到的

于 2019-05-23T12:42:46.770 回答
4

这对我有用!

首先你需要创建 package.json 文件npm init

然后npx create-react-app myapp

于 2019-12-17T08:47:15.120 回答
1

有时会因为网速慢而发生。试试这个。

 npx create-react-app <app name> -timeout=60000

默认超时 = 30000(30 秒)。如有必要,增加超时。

于 2020-11-30T18:04:39.810 回答
1

问题出现的原因有很多。

    1. 如果缺少安装您的反应应用程序所需的节点模块之一,则会发生这种情况。
    1. 另一个原因是如果您的网络连接不稳定
    1. 有时,但在极少数情况下,您的防病毒软件可能会认为缓存中的 cmd 文件是恶意软件。

如果您的防病毒软件是您的问题,请在运行命令期间禁用它。

无论 npx create-react-app 无法在您的计算机上运行的原因是什么,请按顺序运行以下命令:

npm cache clean --force 
npx create-react-app my-app  

让我知道这是否对您有用

于 2020-12-26T06:28:31.747 回答
1

存在错误,因为您的用户 pc 名称包含空格,您可以使用以下代码解决此问题:

> npm config set cache "C:\Users\mycomputer~1name\AppData\Roaming\npm-cache" --global
于 2021-02-22T06:10:30.307 回答
1

同样的问题,这是我的解决方案。

npm 缓存清除 --force

在此处输入图像描述

于 2021-01-21T10:39:07.103 回答
1
  • 在您的防病毒白名单中,节点软件

  • 嘿伙计们,在我看来,检查您的系统是否有任何防病毒软件正在运行并更具体地阻止 node.exe(ByteFence 反恶意软件)

  • 在我的情况下,它阻止了节点系统调用

  • 我从系统托盘中的隐藏图标中退出了它对我来说很好

当你这样做时 => npm start

  • 您可能已经看到某些防病毒软件要求允许将其添加到白名单或将其添加到您应该停止或添加白名单的防病毒软件的阻止列表
于 2021-01-01T11:47:50.237 回答
0
npm uninstall -g create-react-app
npx create-react-app my-app

你不需要全局安装 create-react-app 包。'npx' 已经安装了最新版本。

快速开始

于 2020-07-13T08:29:37.920 回答
0

尝试这个:

npm cache clean --force
npx create-react-app myapp

它对我有用。

于 2021-04-30T07:02:49.250 回答
0

npm cache clean --force

npx create-react-app project_name --template all

cd 项目名称

npm 开始

于 2021-03-17T05:47:37.780 回答
0

以管理员身份运行 Windows PowerShell 并键入:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

于 2020-01-19T10:47:28.617 回答
0
  1. In your antivirus whitelist the node software

  2. hey guys in my point of view, check your system any antivirus is running and blocking the node.exe more specifically (ByteFence Anti-malware)

  3. In my case its blocking the node system call

  4. I quit this from hidden icons in the system tray it works fine for me

when you do

npm start

  • sometimes you may seen some antivirus asks permission to add it to whitelist or add it to block list that antivirus you should stop or add whitelist to it

于 2020-08-28T15:56:21.917 回答
0

请跑npm cache clean --force

如果您正在使用VS code,请确保您restart是终端。

启动新项目就可以了。

于 2022-01-23T06:57:53.280 回答
0

这对我有用: 因为我有网络问题

npx create-react-app <app name> -timeout=60000
于 2021-02-23T10:20:47.350 回答
0

我尝试了一切,但没有任何效果。

然后我重新启动了我的笔记本电脑,当我尝试npm init跟随时,npm install create-react-app我收到了 Avast 潜在有害文件警报,但没关系,我确认了。那次create-react-app尝试失败了,但是当我再次尝试时,它成功了。

防火墙等可能会阻止节点执行功能,因此为什么它会抛出从未调用过的回调()错误。

于 2020-12-08T23:29:43.943 回答
0

这对我有用。

npm cache clean --force
npm init -y
npx create-react-app my-app
于 2021-01-30T14:20:14.513 回答
-1
  1. sudo chown -R 1000:1000 "/home/aditya/.npm"
  2. npx 板条箱反应应用

这应该可以解决问题。

于 2019-12-09T16:03:57.110 回答
-1

如果您无法创建应用程序,请尝试重新安装 32 位 nodeJS 并尝试。

于 2020-04-15T13:24:06.500 回答