【问题标题】:I can't install react using npx create-react-app?我无法使用 npx create-react-app 安装反应?
【发布时间】:2019-05-08 12:50:00
【问题描述】:

我正在尝试使用 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 ]

【问题讨论】:

  • 尝试npm cache clean --force 然后运行npm install -g create-react-app@latest
  • 这是正确的命令,非常感谢。
  • 你的问题用npm cache clean --force命令解决了吗??
  • 尝试npm cache clean --force 然后运行npx create-react-app project_name --template all

标签: reactjs npm create-react-app npx


【解决方案1】:

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

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=pCgDRgmfilE学习了

【讨论】:

  • 下面的一组命令对我有用……但npx 一个不行……你能说出为什么会这样吗?
【解决方案2】:

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

npm init
npm install create-react-app
npx create-react-app myapp

【讨论】:

  • 工作 - Windows 10
  • 它正在工作,谢谢。但是为什么它不能在 Windows 中直接使用命令(npx create-react-app frontend)?
  • 我不需要第一步。
【解决方案3】:

清理 npm 缓存:

npm cache clean --force

然后再试一次

【讨论】:

  • 非常棒的解决方案,继续努力。
【解决方案4】:
  1. sudo chown -R 1000:1000 "/home/aditya/.npm"
  2. npx crate-react-app

这应该可以解决问题。

【讨论】:

    【解决方案5】:

    这对我有用!!

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

    然后npx create-react-app myapp

    【讨论】:

    • 这是唯一对我有用的解决方案
    【解决方案6】:

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

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

    【讨论】:

      【解决方案7】:

      我遇到了同样的问题“安装 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/

      【讨论】:

        【解决方案8】:

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

        【讨论】:

          【解决方案9】:

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

          npm cache clean --force
          

          然后按照these 的步骤升级您的 npm 版本或输入:

          npm install -g npm@next
          

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

          重启终端并输入:

          npx create-react-app my-app
          

          这有望解决您的问题。

          【讨论】:

            【解决方案10】:
            npm uninstall -g create-react-app
            npx create-react-app my-app
            

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

            Quick start

            【讨论】:

              【解决方案11】:
              1. 在您的防病毒白名单中的节点软件

              2. 大家好,在我看来,检查你的系统是否有任何杀毒软件 运行和阻止 node.exe 更具体地说 (ByteFence Anti-malware)

              3. 在我的例子中,它阻塞了节点系统调用

              4. 我退出这个隐藏图标 在系统托盘中对我来说很好用

              当你这样做时

              npm 开始

              • 有时您可能会看到某些防病毒软件请求允许将其添加到 白名单或将其添加到您应该停止的防病毒软件的阻止列表中,或 添加白名单

              【讨论】:

                【解决方案12】:

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

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

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

                【讨论】:

                  【解决方案13】:

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

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

                  有可能是防火墙或类似的东西阻止了节点执行某个功能,因此它抛出了一个从未调用过的回调()错误。

                  【讨论】:

                    【解决方案14】:

                    问题出现的原因有很多。

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

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

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

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

                    让我知道这是否适合你

                    【讨论】:

                    • 这对我有用。我第一次尝试 npx 命令时,一切似乎都很顺利,直到它打印出“未提供模板”。我运行了“npm cache clean --force”,然后运行了 npx 命令,这一次它按预期安装了模板依赖项。谢谢!
                    【解决方案15】:
                    • 在您的防病毒白名单中的节点软件

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

                    • 在我的例子中,它阻塞了节点系统调用

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

                    当你这样做时 => npm start

                    • 您可能已经看到某些防病毒软件请求允许将其添加到白名单或将其添加到您应该停止的防病毒软件的阻止列表或将其添加到白名单

                    【讨论】:

                    • 非常感谢。它真的帮了很多忙。我继续尝试所有解决方案,但没有奏效。问题仅由防病毒引起。
                    【解决方案16】:

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

                    npm 缓存清除 --force

                    【讨论】:

                      【解决方案17】:

                      这对我有用。

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

                      【讨论】:

                        【解决方案18】:

                        存在错误,因为您的用户 pc 名称包含空格, 你可以用这段代码解决这个问题:

                        > npm config set cache "C:\Users\mycomputer~1name\AppData\Roaming\npm-cache" --global
                        

                        【讨论】:

                          【解决方案19】:

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

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

                          【讨论】:

                            【解决方案20】:

                            npm cache clean --force

                            npx create-react-app project_name --template all

                            cd 项目名称

                            npm 开始

                            【讨论】:

                              【解决方案21】:

                              试试这个:

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

                              它对我有用。

                              【讨论】:

                              • 请尝试添加为什么要执行这些命令以及它们执行什么,因为它不应该对用户造成任何进一步的错误
                              猜你喜欢
                              • 1970-01-01
                              • 2020-10-22
                              • 1970-01-01
                              • 1970-01-01
                              • 1970-01-01
                              • 2022-10-20
                              • 2022-06-14
                              • 1970-01-01
                              • 1970-01-01
                              相关资源
                              最近更新 更多