npx create-react-app my-app 命令出错

npx create-react-app my-app command gives an error

我想启动我的 React 应用程序,所以我写了这个命令:

npx create-react-app my-app

但是它给出了这种类型的错误...

npm ERR! Unexpected end of JSON input while parsing near '...sion":"6.1.0","depend'
npm ERR! A complete log of this run can be found in:  
npm ERR!     C:\Users\Dobriya\AppData\Roaming\npm-cache\_logs20-04-27T13_19_55_877Z-debug.log     
Install for [ 'create-react-app@latest' ] failed with code 1

我的版本:

node: 12.16.2      
npm: 6.14.4

这是日志文件:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Program Files\nodejs\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\Dobriya\AppData\Roaming\npm-cache\_npx\17096',
1 verbose cli   '--loglevel',
1 verbose cli   'error',
1 verbose cli   '--json'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v12.16.2
4 verbose npm-session 1196e2875ad9fe18
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://registry.npmjs.org/create-react-app 13280ms
8 http fetch GET 200 https://registry.npmjs.org/create-react-app/-/create-react-app-3.4.1.tgz 1448ms
9 silly pacote tag manifest for create-react-app@latest fetched in 14785ms
10 timing stage:loadCurrentTree Completed in 14810ms
11 silly install loadIdealTree
12 silly install cloneCurrentTreeToIdealTree
13 timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
14 silly install loadShrinkwrap
15 timing stage:loadIdealTree:loadShrinkwrap Completed in 4ms
16 silly install loadAllDepsIntoIdealTree
17 silly resolveWithNewModule create-react-app@3.4.1 checking installable status
18 http fetch GET 200 https://registry.npmjs.org/chalk 276ms
19 http fetch GET 200 https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz 93ms
20 silly pacote version manifest for chalk@3.0.0 fetched in 397ms
21 silly resolveWithNewModule chalk@3.0.0 checking installable status
22 http fetch GET 200 https://registry.npmjs.org/commander 459ms
23 http fetch GET 200 https://registry.npmjs.org/hyperquest 516ms
24 http fetch GET 200 https://registry.npmjs.org/semver 514ms
25 http fetch GET 200 https://registry.npmjs.org/fs-extra 525ms
26 http fetch GET 200 https://registry.npmjs.org/tar-pack 515ms
27 http fetch GET 200 https://registry.npmjs.org/tmp 515ms
28 http fetch GET 200 https://registry.npmjs.org/envinfo 531ms
29 http fetch GET 200 https://registry.npmjs.org/validate-npm-package-name 208ms
30 http fetch GET 200 https://registry.npmjs.org/cross-spawn 700ms
31 http fetch GET 200 https://registry.npmjs.org/inquirer 689ms
32 http fetch GET 200 https://registry.npmjs.org/commander/-/commander-4.1.0.tgz 365ms
33 http fetch GET 200 https://registry.npmjs.org/hyperquest/-/hyperquest-2.1.3.tgz 293ms
34 http fetch GET 200 https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz 292ms
35 http fetch GET 200 https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz 298ms
36 http fetch GET 200 https://registry.npmjs.org/semver/-/semver-6.3.0.tgz 300ms
37 http fetch GET 200 https://registry.npmjs.org/tar-pack/-/tar-pack-3.4.1.tgz 297ms
38 silly pacote version manifest for commander@4.1.0 fetched in 848ms
39 silly resolveWithNewModule commander@4.1.0 checking installable status
40 silly pacote version manifest for hyperquest@2.1.3 fetched in 834ms
41 silly resolveWithNewModule hyperquest@2.1.3 checking installable status
42 silly pacote version manifest for tmp@0.1.0 fetched in 855ms
43 silly resolveWithNewModule tmp@0.1.0 checking installable status
44 silly pacote version manifest for fs-extra@8.1.0 fetched in 875ms
45 silly resolveWithNewModule fs-extra@8.1.0 checking installable status
46 silly pacote version manifest for semver@6.3.0 fetched in 866ms
47 silly resolveWithNewModule semver@6.3.0 checking installable status
48 silly pacote version manifest for tar-pack@3.4.1 fetched in 869ms
49 silly resolveWithNewModule tar-pack@3.4.1 checking installable status
50 http fetch GET 200 https://registry.npmjs.org/envinfo/-/envinfo-7.5.0.tgz 347ms
51 silly pacote version manifest for envinfo@7.5.0 fetched in 894ms
52 silly resolveWithNewModule envinfo@7.5.0 checking installable status
53 http fetch GET 200 https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz 573ms
54 http fetch GET 200 https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz 479ms
55 http fetch GET 200 https://registry.npmjs.org/inquirer/-/inquirer-7.0.4.tgz 476ms
56 silly pacote version manifest for validate-npm-package-name@3.0.0 fetched in 797ms
57 silly resolveWithNewModule validate-npm-package-name@3.0.0 checking installable status
58 silly pacote version manifest for cross-spawn@7.0.1 fetched in 1193ms
59 silly resolveWithNewModule cross-spawn@7.0.1 checking installable status
60 silly pacote version manifest for inquirer@7.0.4 fetched in 1181ms
61 silly resolveWithNewModule inquirer@7.0.4 checking installable status
62 http fetch GET 200 https://registry.npmjs.org/ansi-styles 462ms
63 http fetch GET 200 https://registry.npmjs.org/supports-color 467ms
64 http fetch GET 200 https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz 99ms
65 http fetch GET 200 https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz 95ms
66 silly pacote range manifest for ansi-styles@^4.1.0 fetched in 585ms
67 silly resolveWithNewModule ansi-styles@4.2.1 checking installable status
68 silly pacote range manifest for supports-color@^7.1.0 fetched in 584ms
69 silly resolveWithNewModule supports-color@7.1.0 checking installable status
70 http fetch GET 200 https://registry.npmjs.org/@types%2fcolor-name 232ms
71 http fetch GET 200 https://registry.npmjs.org/color-convert 239ms
72 http fetch GET 200 https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz 2256ms
73 http fetch GET 200 https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz 2257ms
74 silly pacote range manifest for @types/color-name@^1.1.1 fetched in 2513ms
75 silly resolveWithNewModule @types/color-name@1.1.1 checking installable status
76 silly pacote range manifest for color-convert@^2.0.1 fetched in 2519ms
77 silly resolveWithNewModule color-convert@2.0.1 checking installable status
78 http fetch GET 200 https://registry.npmjs.org/color-name 998ms
79 http fetch GET 200 https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz 2789ms
80 silly pacote range manifest for color-name@~1.1.4 fetched in 3806ms
81 silly resolveWithNewModule color-name@1.1.4 checking installable status
82 http fetch GET 200 https://registry.npmjs.org/has-flag 1350ms
83 http fetch GET 200 https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz 253ms
84 silly pacote range manifest for has-flag@^4.0.0 fetched in 1621ms
85 silly resolveWithNewModule has-flag@4.0.0 checking installable status
86 http fetch GET 200 https://registry.npmjs.org/path-key 296ms
87 http fetch GET 200 https://registry.npmjs.org/which 375ms
88 http fetch GET 200 https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz 290ms
89 silly pacote range manifest for path-key@^3.1.0 fetched in 606ms
90 silly resolveWithNewModule path-key@3.1.1 checking installable status
91 http fetch GET 200 https://registry.npmjs.org/shebang-command 1895ms
92 http fetch GET 200 https://registry.npmjs.org/which/-/which-2.0.2.tgz 1522ms
93 silly pacote range manifest for which@^2.0.1 fetched in 1916ms
94 silly resolveWithNewModule which@2.0.2 checking installable status
95 http fetch GET 200 https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz 1575ms
96 silly pacote range manifest for shebang-command@^2.0.0 fetched in 3488ms
97 silly resolveWithNewModule shebang-command@2.0.0 checking installable status
98 http fetch GET 200 https://registry.npmjs.org/shebang-regex 1831ms
99 http fetch GET 200 https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz 118ms
100 silly pacote range manifest for shebang-regex@^3.0.0 fetched in 1974ms
101 silly resolveWithNewModule shebang-regex@3.0.0 checking installable status
102 http fetch GET 200 https://registry.npmjs.org/isexe 1053ms
103 http fetch GET 200 https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz 540ms
104 silly pacote range manifest for isexe@^2.0.0 fetched in 1610ms
105 silly resolveWithNewModule isexe@2.0.0 checking installable status
106 http fetch GET 200 https://registry.npmjs.org/jsonfile 465ms
107 http fetch GET 200 https://registry.npmjs.org/universalify 789ms
108 http fetch GET 200 https://registry.npmjs.org/graceful-fs 809ms
109 http fetch GET 200 https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz 563ms
110 silly pacote range manifest for jsonfile@^4.0.0 fetched in 1046ms
111 silly resolveWithNewModule jsonfile@4.0.0 checking installable status
112 http fetch GET 200 https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz 704ms
113 http fetch GET 200 https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz 699ms
114 silly pacote range manifest for universalify@^0.1.0 fetched in 1519ms
115 silly resolveWithNewModule universalify@0.1.2 checking installable status
116 silly pacote range manifest for graceful-fs@^4.2.0 fetched in 1531ms
117 silly resolveWithNewModule graceful-fs@4.2.3 checking installable status
118 http fetch GET 200 https://registry.npmjs.org/buffer-from 2077ms
119 http fetch GET 200 https://registry.npmjs.org/through2 2518ms
120 http fetch GET 200 https://registry.npmjs.org/duplexer2 2634ms
121 http fetch GET 200 https://registry.npmjs.org/buffer-from/-/buffer-from-0.1.2.tgz 1421ms
122 silly pacote range manifest for buffer-from@^0.1.1 fetched in 3518ms
123 silly resolveWithNewModule buffer-from@0.1.2 checking installable status
124 http fetch GET 200 https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz 1272ms
125 silly pacote range manifest for duplexer2@~0.0.2 fetched in 3926ms
126 silly resolveWithNewModule duplexer2@0.0.2 checking installable status
127 http fetch GET 200 https://registry.npmjs.org/through2/-/through2-0.6.5.tgz 1737ms
128 silly pacote range manifest for through2@~0.6.3 fetched in 4279ms
129 silly resolveWithNewModule through2@0.6.5 checking installable status
130 http fetch GET 200 https://registry.npmjs.org/readable-stream 737ms
131 http fetch GET 200 https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz 1299ms
132 silly pacote range manifest for readable-stream@~1.1.9 fetched in 2062ms
133 silly resolveWithNewModule readable-stream@1.1.14 checking installable status
134 http fetch GET 200 https://registry.npmjs.org/inherits 409ms
135 http fetch GET 200 https://registry.npmjs.org/string_decoder 414ms
136 http fetch GET 200 https://registry.npmjs.org/isarray 418ms
137 http fetch GET 200 https://registry.npmjs.org/core-util-is 456ms
138 http fetch GET 200 https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz 190ms
139 http fetch GET 200 https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz 194ms
140 silly pacote range manifest for inherits@~2.0.1 fetched in 620ms
141 silly resolveWithNewModule inherits@2.0.4 checking installable status
142 silly pacote range manifest for string_decoder@~0.10.x fetched in 629ms
143 silly resolveWithNewModule string_decoder@0.10.31 checking installable status
144 http fetch GET 200 https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz 209ms
145 http fetch GET 200 https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz 181ms
146 silly pacote version manifest for isarray@0.0.1 fetched in 1875ms
147 silly resolveWithNewModule isarray@0.0.1 checking installable status
148 silly pacote range manifest for core-util-is@~1.0.0 fetched in 1882ms
149 silly resolveWithNewModule core-util-is@1.0.2 checking installable status
150 http fetch GET 200 https://registry.npmjs.org/xtend 129ms
151 http fetch GET 200 https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz 125ms
152 silly pacote range manifest for readable-stream@>=1.0.33-1 <1.1.0-0 fetched in 152ms
153 silly resolveWithNewModule readable-stream@1.0.34 checking installable status
154 http fetch GET 200 https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz 490ms
155 silly pacote range manifest for xtend@>=4.0.0 <4.1.0-0 fetched in 644ms
156 silly resolveWithNewModule xtend@4.0.2 checking installable status
157 http fetch GET 200 https://registry.npmjs.org/cli-cursor 413ms
158 http fetch GET 200 https://registry.npmjs.org/ansi-escapes 424ms
159 http fetch GET 200 https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz 1669ms
160 http fetch GET 200 https://registry.npmjs.org/figures 1692ms
161 http fetch GET 200 https://registry.npmjs.org/run-async 1691ms
162 http fetch GET 200 https://registry.npmjs.org/external-editor 1698ms
163 http fetch GET 200 https://registry.npmjs.org/cli-width 1706ms
164 http fetch GET 200 https://registry.npmjs.org/mute-stream 1704ms
165 http fetch GET 200 https://registry.npmjs.org/lodash 1712ms
166 silly pacote range manifest for chalk@^2.4.2 fetched in 1748ms
167 silly resolveWithNewModule chalk@2.4.2 checking installable status
168 http fetch GET 200 https://registry.npmjs.org/rxjs 11500ms
169 silly fetchPackageMetaData error for rxjs@^6.5.3 Unexpected end of JSON input while parsing near '...sion":"6.1.0","depend'
170 silly fetchPackageMetaData error for strip-ansi@^5.1.0 request to https://registry.npmjs.org/strip-ansi failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
171 silly fetchPackageMetaData error for through@^2.3.6 request to https://registry.npmjs.org/through failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
172 silly fetchPackageMetaData error for ansi-escapes@^4.2.1 request to https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
173 silly fetchPackageMetaData error for cli-cursor@^3.1.0 request to https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
174 silly fetchPackageMetaData error for figures@^3.0.0 request to https://registry.npmjs.org/figures/-/figures-3.2.0.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
175 silly fetchPackageMetaData error for mute-stream@0.0.8 request to https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
176 silly fetchPackageMetaData error for external-editor@^3.0.3 request to https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
177 silly fetchPackageMetaData error for run-async@^2.2.0 request to https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
178 silly fetchPackageMetaData error for cli-width@^2.0.0 request to https://registry.npmjs.org/cli-width/-/cli-width-2.2.1.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
179 silly fetchPackageMetaData error for lodash@^4.17.15 request to https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
180 silly fetchPackageMetaData error for string-width@^4.1.0 request to https://registry.npmjs.org/string-width failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
181 timing stage:rollbackFailedOptional Completed in 2ms
182 timing stage:runTopLevelLifecycles Completed in 64346ms
183 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...sion":"6.1.0","depend'
183 verbose stack     at JSON.parse (<anonymous>)
183 verbose stack     at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
183 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50
183 verbose stack     at runMicrotasks (<anonymous>)
183 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:97:5)
184 verbose cwd E:\Files\Sem6\WT\react
185 verbose Windows_NT 10.0.18363
186 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "create-react-app@latest" "--global" "--prefix" "C:\Users\Dobriya\AppData\Roaming\npm-cache\_npx\17096" "--loglevel" "error" "--json"
187 verbose node v12.16.2
188 verbose npm  v6.14.4
189 error Unexpected end of JSON input while parsing near '...sion":"6.1.0","depend'
190 verbose exit [ 1, true ]

尝试以下步骤:

清除 npm 缓存

npm cache clean

现在创建 React 应用如下

 `npx create-react-app my-app`

注意:如果仍然无法正常工作,请执行 npm cache clean --force 然后 运行 npx 命令

If you've previously installed create-react-app globally via npm install -g create-react-app, then you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

Also, npx create-react-app my-app is a command to create a react app not to start the app, to start app run npm start in the project directory

请试试这个:

npm cache verify

这对我有用

我正在使用 npm install -g create-react-app 创建 React 应用程序。 然后 create-react-app hello-react 失败并出现错误

module not found package.json react
Cannot find module '/usr/local/lib/node_modules/create-react-app/node_modules/builtins/builtins.json'. Please verify that the package.json has a valid "main" entry...

创建应用程序总是失败

node --version
v14.15.4
npm --version
6.14.10

根据建议,我使用了以下有助于解决此问题的命令。

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

非常感谢您分享详细信息。

如果 运行清理 npm 缓存本身不起作用(它没有为我做)。试试这个:

  • 转到您的 npm-cache 目录。 windows 这是 C:/Users/{你的用户}/AppData/Roaming/npm-cache。 (当 运行ning npm cache clean --force 那里名为 _cacache 的文件夹被清理,但 _npx 文件夹没有)。

  • 进入 _npx 文件夹并删除其中的所有内容。之后,转到您的终端并再次 运行 npm cache clean --force

  • 运行 npx create-react-app my-app 再一次。

我在其他任何地方都找不到这个答案,并且在这个烦人的问题上被困了几个星期。这为我解决了。

我还看到一些人在尝试创建新的 React 应用程序时遇到超时问题。我也遇到了这个问题,并通过转到我的 .npmrc(位于 C:/Users/{your user}/.npmrc 并添加行 timeout=240000 来解决它,如果你有真的很慢的网络或 vpn 让你的生活变得像地狱一样。