When I create React app It's not creating - javascript

I am beginner in react js
I'm Create react app it's give me a error I am trying to do all the things
cmd to create app
npx create-react-app my-app or npx create-react-app#latest your-app-name --use-npm
error
npx create-react-app my-reactchat-app
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dp312\AppData\Roaming\npm-cache\_logs\2023-01-25T22_46_04_461Z-debug.log
Install for [ 'create-react-app#latest' ] failed with code 1
I'm try to do this cmd in both mode administrator mode also
npm cache clean --force
when run this cmd
npm create-react-app my-app
it's give me error like this
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\dp312\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#6.14.15 C:\Program Files\nodejs\node_modules\npm
try to do this also but still error not soul
how to solve this error ?
anyone can help me

Define the node engines config in package.json
Also, check your node version keep it latest.
Check if you're running the app from inside of your app folder.

Related

npm ERR! code E401 npm ERR! Incorrect or missing password

My Node version is 10.15.0 and NPM version is 6.8.4
On running npm install after upgrading
npm to 14.16.0 and npm to 7.6.2
Getting this error -
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xyz/.npm/_logs/2021-04-15T18_55_07_993Z-debug.log
Try Deleting the package-lock.json file before running the command "npm install" after upgrading the node versions, if you have not done that.
If that will not work try removing the .npmrc file in $HOME directory as mentioned in this post.
NPM ERR Code E401: Unable to authenticate, need: Bearer authorization
Note - Deleting package-lock.json can have its own issues as mentioned in this posts, so go with this solution unless you find any better solution.
Deleting `package-lock.json` to Resolve Conflicts quickly
In the directory C/Users/your-windows-username/
delete the following files:
.cache
.package
.package-lock
.npmrc
After that, go to your project and run the following command in your terminal
npm i
I had the same error with the company registry configured in .npmrc
registry=https:<company-registry-url>
Node version : 19.1.0
NPM version : 8.19.3
Solution:
Execute npm login
$ npm login
npm notice Log in on https:<registry-url>
Username: xxxx
Password:
Email: (this IS public) (xxxx)
Logged in as xxx on https:<registry-url>.
After this .npmrc got updated with
//<registry-url>/:_authToken=xxxxx
Your password in .npmrc must be base64 encoded. Easy to screw up just copy-pasting the password, need to base64 encode that.
I have been getting the same error recently on various projects after running npm run dev:
npm ERR! code E401
npm ERR! Incorrect or missing password.
What fixed it for me was to delete my package-lock.json file (and any yarn.lock files, which might create conflicts with npm) and the node_modules directory. Then I updated my npm packages with npm update. (CAUTION: Before updating any npm packages, you should probably create a new Git branch and run npm update in that new branch. If you run into bigger problems after the updates, then you can revert back to your previous branch.)
After my packages were updated, then running my npm startup script (e.g. npm run dev) worked again without errors.
NOTE: You can run npm outdated to see which of your npm packages could use an update.
Had the same issue with Node 16.x.x.
I have done everything from this topic and those topics which were mentioned here and nothing helped me!
The only thing that helped me to login was that I have deleted Node 16.x.x and installed Node 14.8.1 from here - https://nodejs.org/en/download/releases/
It can be happening because of a bug on npm. This was happening to me with npm v7. Switched to v6 and it worked.
More context: https://github.com/npm/cli/pull/2153
Reinstall the lastest node.js. That fixed my issue.

"npm ERR! unexpected end of JSON input near" while creating a new react app

[enter image description here][1]npm
I am trying for so many times to create a app in react but every time the CMD showing an ERR!
here is code :
Microsoft Windows [Version 10.0.18363.476]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Sumit>E:
The system cannot find the drive specified.
C:\Users\Sumit>D:
D:>React js
'React' is not recognized as an internal or external command,
operable program or batch file.
D:>react js
'react' is not recognized as an internal or external command,
operable program or batch file.
D:>React js
'React' is not recognized as an internal or external command,
operable program or batch file.
D:>create-react-app my_react
Creating a new React app in D:\my_react.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react (over 30000ms)
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_33_43_496Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my_react / from D:\
Done.
D:>create-react-app my-react-app
Creating a new React app in D:\my-react-app.
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 '...Y3hEcJW8se9P4K6+GYGu9'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_34_57_334Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my-react-app / from D:\
Done.
D:>create-react-app new-react
Creating a new React app in D:\new-react.
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 '...gAAwSQP/RpJCkm/rgw8jt'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_38_28_735Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting new-react / from D:\
Done.
D:>npm create-react-app my-react-aplication
Usage: npm
where is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm -h quick help on
npm -l display full usage info
npm help search for help on
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\Sumit.npmrc
or on the command line via: npm --key value
Config info can be viewed via: npm help config
npm#6.14.4 C:\Program Files\nodejs\node_modules\npm
D:>npx create-react-app my-react
Creating a new React app in D:\my-react.
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 '...gAAwSQP/RpJCkm/rgw8jt'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_54_02_126Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my-react / from D:\
Done.
D:>
if you didn't install npm in general mode, it should better you do it with this comment in the root with the command
npm install -g
, or if you did it before you need to update it with the command
npm update [-g]
There are two things that you can do that might possibily help you resolve the issue you are facing.
1.If you are on a slow internet connection you might have to increase the timeout from 30s to 60s by adding this to your .npmrc file:
timeout=6000
You can find the .npmrc file at the path:
C:\Program Files\nodejs\node_modules\npm
2. This issue might be due to npm version mismatch, you can try to install the latest npm version by typing the following command in cmd:
npm install -g npm
Hope this helps!!

Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app"

When I was trying to create a new react app using npx create-react-app example_app, I get this error
[Your cache folder contains root-owned files, due to a bug in previous
versions of npm which has since been addressed sudo chown -R 0:0
"/root/.npm"]
I even tried to re-install create-react-app again using npm i create-react-app, it is giving the same kind of
error.
I assume after searching about it that it is due to some permissions issue. My current user doesn't have permission to /home/shubham/.npm where shubham is my username, but I am not so sure about this.
I have tried to solve this error using chown command as
sudo chown -R <username>:<groupname> /home/shubham/.npm"
where <username> is Shubham and <groupame> is 1000, but it is still not working.
Request people to help me out.
If you need any more information, let me know.
This worked for me:
sudo npm cache clean --force
This is what helped me after going through the above answers. I hope it helps someone else too. After re-reading the npm error prompt, I adjusted the provided command to include the .npm path given in the error message. Below is a copy of my original error messages.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/vagrant/.npm-global/lib/node_modules
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 900:900 "/home/vagrant/.npm"
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2020-07-09T16_43_35_046Z-debug.log
[ExecStack] Exit code 243 Time 01:03
[error] Executing target-hook frontend-reqs failed.
[error] Command source:build:frontend-reqs exited with code 1.
Instead of using sudo chown -R 900:900 "/home/vagrant/.npm", I used sudo chown -R 900:900 "/home/vagrant/.npm-global". After that, I was able to use the previous command that caused the error with no issues.
Set the npm_config_cache environment variable
in linux
export npm_config_cache=/path/to/cache
in windows
set npm_config_cache=/path/to/cache
Try sudo chown -R 1000:1000 "/home/shubham/.npm"
I had to do both the root folder and the root/.npm
sudo chown -R 1001:1001 "/root"
sudo chown -R 1001:1001 "/root/.npm"
If you are using CI and share the CI slave with other teams, maybe not possible to sudo chown -R {group}:{user} "~/.npm" (i.e.: using Github Enterprise with Github Actions on shared runners
I add
# use local cache to work-around 'npm ERR! path ~/.npm/_locks/staging-xxx.lock' in GHA
cache=./npm-cache
into my .npmrc in the repo to solve the issue by using local npm cache dir
I had the same issue and several others while trying to update my npm packages. I will be honest I do not have enough knowledge of package handlers or why this fixed my situation, but I believe my version of npm and npx were causing the issues. I had errors immediately trying to install npx, node and create-react-app with my old and out of date version of npm.
I could not run npm install npx -g without --force. Once I did that I also ran npm install npm -g --force. After this I could already tell things were different.
After npm and npx were completely overwritten, I ran npm install node -g and npm install create-react-app -g without any weird problems. I created a new react app and started it error free.
(I also ran the cache command before all of this. sudo npm cache clean --force which I am unsure if it helped).
I was getting this while running npx #11ty/eleventy as root:
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 1000:1000 "/root/.npm"
No, /root/.npm is supposed to be owned by root. It's not at all due to a bug in a previous version of npm. And yes, the root user has permission to read and write that directory. So this is a bug in the current version of npm that prevents building the project as root.
Of course following the nonsensical instructions to change the root homedir's ownership does not work.
In my case, I was running it as root as part of a build script that needs root for an rsync to complete:
#!/bin/bash -eu
# mybuildscript
npx #11ty/eleventy
rsync _site/ /srv/www/ # This needs to be run as root
So my workaround was to run that single line as an unprivileged user using sudo:
#!/bin/bash -eu
# mybuildscript
sudo -u ki9 npx #11ty/eleventy
rsync _site/ /srv/www/ # This needs to be run as root
I am using npm version 7.5.2. Hopefully this will be addressed in a future version of npm.
I also tried all of the above steps on my MAC Catalina, but didn't resolve my issue. These steps resolved my problem:
npm update
npx --ignore-existing create-react-app my-app
Thanks to this comment
This will work:
sudo chown -R 1000:1000 "~/.npm"
Neither force-cleaning the cache nor using chown worked for me, but deleting the folder did work and fixed the issue.
My error was:
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 501:20 "/Users/aw/.npm"
The fix was to permanently erase the .npm folder in question, which I did using rm -rf:
sudo rm -rf /Users/aw/.npm
(Mandatory warning: this is a dangerous command if you typo it.)
I encountered the same issue and the problem with mine was that I was running an older version of npm. After updating npm and removing the .npmrc file, it worked just fine.
npm install -g npm#latest
rm .npmrc
Be careful before deleting the .npmrc file, take a backup as it will reset your npm configuration.
I fixed mine by running:
sudo npm cache clean --force
followed by removing the root owned files.
first, to view the file owners and group:
cd /Users/username/
ls -la
You have to check the owner of .npm, changed to non-root user:
sudo chown -R username:group "/Users/username/.npm"
or for global .npm-global
sudo chown -R username:group "/Users/username/.npm-global"
replace keyword: username/group accordingly
It helped me:
Remove and install npm again
It work for me now!
What I did? (I'm not saying it's the best way to fix this but i'ts working for me. I'm still looking for the best explications for this issue)
sudo rm -Rf /home/[YOUR_USER_NAME]/.npm-global/lib/node_modules/
and run your command again.
My explication is that it seems like something is corrupted in the node_modules's folder.
As it's not risky to delete it I did it and it works now.
Try sudo npx create-react-app example_app or in my case sudo npm install #vue/cli
I tried everything else here, but in the end realised that it might just be the command that I was running was not able to escalate the correct permissions.
Find error in your log file:
verbose Error: EACCES: permission denied, mkdir '/Users/xxx/.tnpm_tmp/npm-52731-e91f6671'
Use that error in your condition.
sudo chown -R 502:20 "/Users/XXX/.tnpm_tmp"
I solve the problem with the following commands
Install dependence > npm install create-react-app
run > create-react-app project_name
happy hack!!
Try to create your react app using yarn package manager.

npm doesn't work ubuntu16.04

I installed nodejs and npm as is written here but after having installed both of them, npm doesn't work. Always that I try to run any command like npm -v, npm version, npm install express, etc. It just print this:
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
explore, get, help, help-search, i, init, install,
install-test, it, link, list, ln, login, logout, ls,
outdated, owner, pack, ping, prefix, profile, prune,
publish, rb, rebuild, repo, restart, root, run, run-script,
s, se, search, set, shrinkwrap, star, stars, start, stop, t,
team, test, token, tst, un, uninstall, unpublish, unstar,
up, update, v, version, view, whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/home/user/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#5.6.0 /usr/lib/node_modules/npm
It's as if the command was registered in the man but doesn't work properly. I'm pretty new on this. I don't get what is wrong with it.
The error is the same as if the sintax of the command were wrong. The print is the same even if I run npm any-string-here.
I already tried to purge nodejs and erase all node_modules and libraries to make a clean install of nodejs and npm but the problem remains. What could be the wrong?
Note: Nodejs works fine. I can run nodejs file.js without problem. It's just npm who is not recognize.

npm package.json scripts not being called

I have the following scripts section in my projects package.json:
"scripts": {
"seed": "node bin/seed",
"test": "echo \"Error: no test specified\" && exit 1"
},
If i run $ npm test I get this:
>npm test
> node-mongo-seeds#0.0.1 test C:\Users\m089269\WebstormProjects\node-mongo-seeds
> echo "Error: no test specified" && exit 1
"Error: no test specified"
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
If i run $ npm seed, I get this:
npm seed
Usage: npm <command>
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, repo, restart, rm,
root, run-script, s, se, search, set, show, shrinkwrap,
star, stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, v,
version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\m089269\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#1.4.3 C:\Program Files\nodejs\node_modules\npm
Why does it recognize my test script but not my seed script?
EDIT
When I try npm run-script seed I get this error which is expected because I don't pass in a -d param:
$ npm run-script seed
> node-mongo-seeds#0.0.1 seed C:\Users\m089269\WebstormProjects\node-mongo-seeds
> node bin/seed
Populate mongo from a set of .json files.
Usage: $ node seed
Options:
-d The path to your mongo db [required]
Missing required arguments: d
npm ERR! node-mongo-seeds#0.0.1 seed: `node bin/seed`
npm ERR! Exit status 1
...
When I try npm run-script seed -d "localhost/ease" I get this error.
npm run-script seed -d localhost/ease-dev
npm info it worked if it ends with ok
npm info using npm#1.4.3
npm info using node#v0.10.26
npm ERR! Error: ENOENT, open 'C:\Users\m089269\WebstormProjects\node-mongo-seeds\node_modules\seed\package.json'
...
Why is it looking for a package.json in node_modules\seed? Seed is not even a dependency.
From the documentation:
npm supports the "scripts" member of the package.json script, for the following scripts:
prepublish: Run BEFORE the package is published. (Also run on local npm install without any arguments.)
prepare: Run both BEFORE the package is packed and published, on local npm install without any arguments, and when installing git dependencies (See below). This is run AFTER prepublish, but BEFORE prepublishOnly.
prepublishOnly: Run BEFORE the package is prepared and packed, ONLY on npm publish.
prepack: run BEFORE a tarball is packed (on npm pack, npm publish, and when installing git dependencies).
postpack: Run AFTER the tarball has been generated and moved to its final destination.
publish, postpublish: Run AFTER the package is published.
preinstall: Run BEFORE the package is installed
install, postinstall: Run AFTER the package is installed.
preuninstall, uninstall: Run BEFORE the package is uninstalled.
postuninstall: Run AFTER the package is uninstalled.
preupdate: Run BEFORE the package is updated with the update command.
update, postupdate: Run AFTER the package is updated with the update command.
pretest, test, posttest: Run by the npm test command.
prestop, stop, poststop: Run by the npm stop command.
prestart, start, poststart: Run by the npm start command.
prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided.
Additionally, arbitrary scripts can be run by doing npm run-script <stage> <pkg>.
You can see the reason why your npm test script works is because npm test is a built-in command. You must use npm run-script if you want to execute a script that is not executed by a built-in npm command.
Custom scripts declared in the package.json can be ran with the npm run <your-script> form in your shell.
Try npm run seed or npm run test
To execute the custom scripts in package.json using below
npm run-script seed
or
npm run-script < custom script >
or you can use
npm run < custom script >

Categories

Resources