npm doesn't work ubuntu16.04 - javascript

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.

Related

When I create React app It's not creating

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.

"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!!

EPERM -4048, operation not permitted, unlink

Whenever I try to install anything with npm install, I get the following error (usually referencing a different path). I've tried npm cache clean but that gets a similar error. I tried restarting the PC and checked for processes that may be using npm. Followed several other answers and none of the ones I've tried have been successful.
The attached screenshot was taken just after uninstalling node, restarting my computer, removing everything about npm from AppData and Program Files etc. and then creating a brand new project to test in. The project and the directory were created in command line.
Any help would be truly appreciated. Thanks!
SCREENSHOT
You are trying to install the npm using the command
npm install -g cordova ionic
But it is supposed to be like
npm install ionic cordova -g
or
npm install -g ionic cordova
For more info check the below link
Error: EPERM: operation not permitted

npm login - Registry returned 401 for PUT

I am trying to login to npm by doing npm login and entering username, password, and email but I am receiving the following response:
Registry returned 401 for PUT
npm is saying that I have the incorrect username or password, but I've used the same credentials to login to npmjs.org.
version of node is:
node -v v6.2.2
Solutions with .npmrc and/or npm config were not working for me.
Eventually found the error was for and older npm version with 2fa enabled (see this thread).
So the following should work
npm update npm -g
npm login
-- update
On a different machine this didn't work until I updated NodeJS and did npm i npm -g.
I guess, that you have overdid registry.
For checking, please, run npm config get registry. You should see
▶ npm config get registry
https://registry.npmjs.org/
If there is not this message, then use npm config set registry https://registry.npmjs.org/
I had an npmrc located at ~/.npmrc and removed it with rm ~/.npmrc and it seemed to fix the issue.
The file contained an authToken in the registry so I suppose it was conflicting with the login?
I'm not sure...

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