I encountered an error and thought I’d post the solution here since it just might happen to you sometime! Here’s the scenario:
I was planning to take the winston npm module out for a spin to try out it’s awesome logging capabilities. I created a directory called winston
to create a project and conduct the test. What would be more logical than that? 🙂
Next, I ran npm init
to create a package.json
file hitting my Enter key as fast as it could go to accept all the defaults for this throwaway test project:
It looks like we are good to go! Let’s go ahead and install winston locally with the --save
flag to save the dependency in the package.json
file.
npm install winston --save
We are greeted with the following error:
npm ERR! Windows_NT 10.0.10586 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Dave\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "winston" npm ERR! node v5.3.0 npm ERR! npm v3.6.0 npm ERR! code ENOSELF npm ERR! Refusing to install winston as a dependency of itself npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! <https://github.com/npm/npm/issues> npm ERR! Please include the following file with any support request: npm ERR! C:\!projects\node\winston\npm-debug.log
Uh oh, this is not looking good. This looks like a serious error. Winston is not able to install a dependency of itself. What is the solution?
Let’s inspect the package.json
file:
{ "name": "winston", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
On line 2, we see that the name of our project is winston
. I don’t think npm likes that since we are trying to install a package named “winston”. Let’s rename our project to “winston-test”, and save the package.json
file:
{ "name": "winston-test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
Let’s now try to install the npm package again:
npm install winston --save
This time, the npm package installs successfully:
[email protected] C:\!projects\node\winston `-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] `-- [email protected] npm WARN [email protected] No description npm WARN [email protected] No repository field.
You will see that npm does give us a couple of warning messages, but these are nothing we need to worry about for testing and learning purposes. We are back in business!
Very Useful. You might want to name the name of your project the same as the module you want to install which make total sense especially if you want to reuse the code. Thank you for the tip
You are very welcome, IsmaelKP. Thanks for taking the time to provide feedback and let me know that this article was useful to you!
thanks Many people were confused
As a beginner developer I really appreciate this information. I wouldn’t have any chance to figure out this problem by myself.
Awesome – thanks for letting me know. So glad this article was helpful to you!
Thank you very much.
Thank you
Very helpful!
Thanks you
Nice tip, really helpful. Cheers
Thank you so much, this saved my day 🙂
Awesome – so glad my article was helpful to you. Thanks for letting me know.
thanks bro , good article
Refusing to install angular as a dependency of itself [SOLVED] 🙂
When I tried to install Angular 1 to Meteor, the same error was occurring. Thank you very much for your solution!!! 🙂
Very, very, very thank you!!!
Ufff! Very useful! Tnks a lot
oo!!! Very helpful thanks a lot
Awesome !! it helped me
it really works for me ,great thanks
Thank You!!! This saved me tonight.
You are very welcome. Thanks for letting me know!
You saved a lot of inanimate objects in my house tonight. Give me a PayPal account and your next round of drinks is on me.
Thanks!
thank you!
very useful
Thank you so much, this saved me ^_^
Thank you very much, I helped a lot with the problem with nmp.
Thanks Alot 😀
thisdavej to the rescue
Thank you. It was very useful
Thank you, i had not clue for this but after reading this its quite clear error message
thanks
Thank you for your sharing to improve my efficiency
Excellent post! Thanks!
Thank you so much!!
How to check if npm install has done its installation and where will be the node_modules located for npm in centos user machine?
Thank you so much!
Thanks a lot for your article 😀
I thank you! Developing community thanks you! The world thanks you! 🙂
Ah, thank you so much. I never would have figured this out on my own.
thanks. saved me a lot of frustration and wasted time!
Thanks. It was so useful. Never thought that would be an error.
thanks, you just made things easy for me
thank you so much! your solution worked for me!
Thanks a lot
it works for me
I finally After I browsed….your solution that works for me
Thanks a lot, that was useful
thanks.. it works for me
Thank you! Perfectly explained and solved my issue just as explained!
Thank you !!!
Still not working in my case ! 🙁
thank you
thanks, very usefull/
thank you so much! 🙂
Glad I found this… You solved my problem perfectly! Thanks 🙂
thank you mate
Thank you so much, I was stuck on this and your solution just rocked it.
Thank you!
I think I love you…
Thank you so much
You saved my day!! Thank you!!
thank you so much
Love You… Thankyou so much you save my day .. This solution is really helpful for me
thanks for the solution . it’s guys like you who help others and thus the coding doesn’t stop
Thanks for the solution. Resolved my problem.
more than a year on … working away on my laptop late night ; mighty kicked with years of node development and I come across this error. Dumbstruck would be an understatement. I see your post and its a RELIEF, because of all the things (lets not get started) that you need to investigate … who would look at the package.json ??! Thank YOU
Vijay, thanks for sharing your story about how my article was able to help you! I was also dumbstruck when I encountered this issue, and I’m glad I took the time to document the solution since it appears to be something that provides an element of surprise/frustration for others too. 🙂
Thanks, That was really helpful
Thanks a lot!
Thank you so much. Great Help 🙂
Thank you so much for the solution 🙂
You saved my day
Kiitoksia!
Muchas gracias!
this is awesome solution.
Thank you very much!
Excelent!
Excellent and Thank you very much.