在Windows 10上通过命令行创建React应用时,我遇到了一种奇怪的情况。运行create-react-app命令时出现以下错误。我正在使用节点v8.9.4和npm v6.4.0。
Creating a new React app in D:\react\myreactapp.
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 '...^1.0.1","line-numbers'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Roaming\npm-cache\_logs\2018-08-26T11_04_03_908Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting myreactapp / from D:\react
Done.
答案 0 :(得分:1)
这可能与您为其指定的项目名称有关。尝试使用大写字母,即仅使用小写字母和连字符。因此,而不是
$ create-react-native-app myApp
使用
$ create-react-native-app my-app
或从错误消息中得出的信息,可能是在应用程序名称(myreactapp)之后添加了一个空格,然后按了反斜杠而不是Enter,然后又按Enter了吗?
另外,请尝试:npm cache clean --force
,如果没有用,yarn cache clean
这可能是由于自述文件中的React-Native安装说明中缺少换行符引起的(此问题已修复),npm install
和npm start
之间导致用户执行{{1} }-它自己安装了npm install npm start
及其所有测试。参见问题:https://github.com/facebook/react-native/issues/20015。
无论如何,如果您运行npm
并告诉我们结果会很好。