Farhan Bin Amin
Farhan Bin Amin

Reputation: 60

npx create-react-app command returns error

So i decided to learn react following a tutorial. According to the tutorial I typed:

npm install -g [email protected]

Then I typed:

create-react-app my-app

After running this I typed:

npm start

It threw some error (I can't remember exactly what the error was. But it was something like package.json didn't include npm start, also it didn't include any template) After a quick google search I found that the previous process was not recommended anymore. According to the guide found here

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

So I typed npm uninstall -g create-react-app in cmd. After uninstalling I closed cmd and deleted the folder which was created created after running npm install -g create-react-app

Then after typing npx create-react-app my-app in cmd. But it returns this error:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "Amin\AppData\Roaming\npm-cache\_npx\4996" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Farhan Bin Amin\AppData\Roaming\npm-cache\_logs\2020-06-24T04_44_56_925Z-debug.log
Install for [ 'create-react-app@latest' ] failed with code 1

The debug log is included below:

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\\Farhan',
1 verbose cli   'Bin',
1 verbose cli   'Amin\\AppData\\Roaming\\npm-cache\\_npx\\4996',
1 verbose cli   '--loglevel',
1 verbose cli   'error',
1 verbose cli   '--json'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 0eec5b00126c667b
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for file:Amin\AppData\Roaming\npm-cache\_npx\4996 Could not install from "Amin\AppData\Roaming\npm-cache\_npx\4996" as it does not contain a package.json file.
8 http fetch GET 404 https://registry.npmjs.org/Bin 124ms
9 http fetch GET 304 https://registry.npmjs.org/create-react-app 178ms (from cache)
10 http fetch GET 404 https://registry.npmjs.org/Bin 39ms
11 silly fetchPackageMetaData error for Bin@latest 404 Not Found - GET https://registry.npmjs.org/Bin - Not found
12 silly pacote tag manifest for create-react-app@latest fetched in 193ms
13 timing stage:rollbackFailedOptional Completed in 0ms
14 timing stage:runTopLevelLifecycles Completed in 201ms
15 verbose stack Error: ENOENT: no such file or directory, open 'F:\react\Amin\AppData\Roaming\npm-cache\_npx\4996\package.json'
16 verbose cwd F:\react
17 verbose Windows_NT 10.0.15063
18 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\\Farhan" "Bin" "Amin\\AppData\\Roaming\\npm-cache\\_npx\\4996" "--loglevel" "error" "--json"
19 verbose node v12.16.3
20 verbose npm  v6.14.4
21 error code ENOLOCAL
22 error Could not install from "Amin\AppData\Roaming\npm-cache\_npx\4996" as it does not contain a package.json file.
23 verbose exit [ 1, true ]

I googled for hours but nothing seems to fix this problem.

UPDATE: So it seems that only yarn create react-app my-app is working. But npm/npx are not. Thanks to @prisar for mentioning to try different method.

Upvotes: 0

Views: 1508

Answers (3)

prisar
prisar

Reputation: 3195

try using npm or yarn instead. there seems to be some problem with npx cache. Once, try to clear the cache also.

Upvotes: 1

prinzu
prinzu

Reputation: 41

I too have that problem earlier. Try to delete node_modules, package-lock.json files from the root folder and run

npm cache clean --force && npm install

and then-

npx create-react-app my-app

Upvotes: 0

Mat Som
Mat Som

Reputation: 120

I think the best reference is the official guide which suggest,

You’ll need to have Node >= 8.10 and npm >= 5.6 on your machine

So after ensuring the requirement, try to uninstall the global create-react-app and run npx instead.

npx create-react-app my-app

I think the tutorial is using the old of installing CRA, I might be wrong.

Upvotes: 0

Related Questions