问题
I am trying to use npx create-react app but i have errors that is shown below:
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**
and the log file of the error is here...!
How I can get rid of this trouble??
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 ]
回答1:
To fix the issue, run these commands in sequence
npm init
npm install create-react-app
npx create-react-app myapp
回答2:
I had the same issue "Install for create-react-app@latest failed with code 7" Use this. It worked for me.
npm install -g create-react-app
npx create-react-app my-app
cd my-app
npm start
for further reference go to: https://www.techomoro.com/how-to-install-and-setup-a-react-app-on-windows-10/
回答3:
Clean npm cache:
npm cache clean --force
then try again
回答4:
First, clear cache by typing this in your terminal:
npm cache clean --force
Then upgrade your version of npm by either following these steps or type:
npm install -g npm@next
Now go to "NodeJS" in Programs and Features in your Windows settings and Repair your installation.
Restart terminal and type:
npx create-react-app my-app
This should hopefully fix your issue.
回答5:
I had the same problem in creating react project when I used commands from official source https://reactjs.org/docs/create-a-new-react-app.html#create-react-app
npx create-react-app my-app
cd my-app
npm start
The above commands din't work on my windows. I have Node >= 6 and npm >= 5.2 on my machine even then it is not able to open localhost:3000 then I used this commands
npm install -g create-react-app
create-react-app my-app-name
cd my-app-name
npm start
It worked perfectly fine. I learned from https://www.youtube.com/watch?v=pCgDRgmfilE
回答6:
This worked for me!!
first you need to create the package.json file by
npm init
then
npx create-react-app myapp
回答7:
when i run the commond npx crate-react-app i face this error what should i do ? please
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm: : not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm: /mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
回答8:
Run Windows PowerShell as administrator and type this:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
回答9:
npm uninstall -g create-react-app
npx create-react-app my-app
You don't need to install the create-react-app package globally. 'npx' is already installing with the latest version.
Quick start
回答10:
- sudo chown -R 1000:1000 "/home/aditya/.npm"
- npx crate-react-app
this should fix the issue.
回答11:
If you are unable to create the app try reinstalling nodeJS in 32-bits and try it.
来源:https://stackoverflow.com/questions/53657920/i-cant-install-react-using-npx-create-react-app