如何安装React应用而不会出现错误

时间:2020-05-23 13:01:32

标签: javascript node.js reactjs react-native npm

您好,我正在尝试将React安装到系统中,但是从2天开始,我现在多次遇到该错误。首先,我使用这些命令来安装react app,对我来说一切正常

1. npm install -g creat-react-app
2. create-react-app reactapp

但是两天后,在选择这些选项进行安装时遇到了错误,因此我访问了https://create-react-app.dev/docs/getting-started/,其中有明确说明-如果您之前已通过npm install -g create-react-app在全球范围内安装了create-react-app ,我们建议您使用npm uninstall -g create-react-app卸载软件包,以确保npx始终使用最新版本。然后我使用了命令npx create-react-app reactapp,但是我遇到了这个错误。我已经多次卸载并安装了nodejs,也使用了npm cache clean --force命令。但是不起作用!!!!

e:\react-learn>npm uninstall -g create-react-app
removed 98 packages in 5.031s

e:\react-learn>npx create-react-app reactapp
npx: installed 98 in 39.888s

Creating a new React app in e:\react-learn\reactapp.

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

npm ERR! Unexpected end of JSON input while parsing near '...wRDiDz3X/FqXhQ==","
sh'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dell\AppData\Roaming\npm-cache\_logs\2020-05-23T12_48_46_9
79Z-debug.log

如何解决此错误?还有一件有趣的事,当我复制上一个项目并运行npm start时,它工作正常。问题是什么reactapp只是吃掉我的神经...

2 个答案:

答案 0 :(得分:0)

尝试清除缓存,然后重试。 您可以运行

npm cache clean --force 

npm cache clear --force

答案 1 :(得分:0)

尝试使用npx create-react-app client --use-npm。有时由于软件包管理器会出现一些问题。