Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

v3.2: Turn ENOENT missing package.json warnings and errors off? #9161

Closed
eush77 opened this issue Aug 4, 2015 · 56 comments
Closed

v3.2: Turn ENOENT missing package.json warnings and errors off? #9161

eush77 opened this issue Aug 4, 2015 · 56 comments

Comments

@eush77
Copy link
Contributor

eush77 commented Aug 4, 2015

Is there going to be a config option to silence warnings and errors telling me that I miss package.json (when in reality this is intentional)?

I often install stuff to temporary directories just to play/experiment and I'm not comfortable seeing these errors all the time.

$ npm install thingy
…
npm WARN ENOENT ENOENT: no such file or directory, open '/tmp/tmpdir/R3semq/package.json'
npm WARN EPACKAGEJSON /tmp/tmpdir/R3semq No description
npm WARN EPACKAGEJSON /tmp/tmpdir/R3semq No repository field.
npm WARN EPACKAGEJSON /tmp/tmpdir/R3semq No README data
npm WARN EPACKAGEJSON /tmp/tmpdir/R3semq No license field.

Or even:

$ npm ls
…
npm ERR! error in /tmp/tmpdir/R3semq: ENOENT: no such file or directory, open '/tmp/tmpdir/R3semq/package.json'
@othiym23
Copy link
Contributor

When I want to test people's repro cases for bugs (which I do many many times a week), this is what I do:

mkdir test-npm-is-being-bad
cd test-npm-is-being-bad
npm init -y
npm install -S package-npm-is-being-bad-to

This silences the warnings and also gives me something to refer to later when I'm trying to remember what I was doing. If you want to turn off warnings altogether, you can run npm --loglevel=error (or even npm config set loglevel=error if you want to be super hardcore about it), but you're going to lose a lot of useful feedback. I don't really see a place for a special config option just to silence these warnings.

eush77 added a commit to eush77/npm-autoinit that referenced this issue Aug 10, 2015
@saper
Copy link
Contributor

saper commented Aug 11, 2015

I am getting this in response to node install node-sass ([npm-debug.log on gist](https://gist.github.com/f0153fa8886c0bb65ec0)) in/tmp`:

npm WARN ENOENT ENOENT: no such file or directory, open '/tmp/package.json'
npm WARN EPACKAGEJSON /tmp No description
npm WARN EPACKAGEJSON /tmp No repository field.
npm WARN EPACKAGEJSON /tmp No README data
npm WARN EPACKAGEJSON /tmp No license field.

This is at least confusing and unnecessary. Kind of violates principle of least astonishment.

And it is not a reason (not even contributing to) the ultimate failure (which is sass/node-sass#1061)

@acarstoiu
Copy link

@othiym23: the real issue here is why are those warnings displayed? What made npm try to consult (cwd)/package.json? Nothing, at least not on the command line.

I believe this ticket was closed too quickly.

@othiym23
Copy link
Contributor

package.json is npm's control file and manifest, and the CLI strongly prefers that package.json exist, to the point of printing out a warning if it's not found. In addition, due to the way that npm (and Node) navigates up the directory tree looking for a package.json when performing many default actions (i.e. npm install --save <packagename>), not having a package.json in the current working directory, even if it's a stub, can lead to far more surprising behavior (i.e. the requested package being installed somewhere unexpected, like your home directory). The current warnings block may be slightly verbose (i.e. if there's no package.json file, it might be useful to just print that, instead of warnings about the missing package.json fields), but I believe that printing a warning about working without a package.json is appropriate.

@acarstoiu
Copy link

We're in the business of computers doing what they are told, not what the operators actually want. Installing packages in unexpected places is one of the possible outcomes.
And indeed, I was referring to the --save* command line options: if any of them was specified, then the lack of a package.json file should be a fatal error. Otherwise, a warning message is unjustified, least the the individual warnings about various fields.

I can see the intention, but over time, any operator will ignore them as noise. That's why they should be conditioned by actual need of package.json.

@saper
Copy link
Contributor

saper commented Apr 17, 2016

So go ahead and disable the possibilty to run npm install in the directory without package.json. "strongly prefers" is a sign of bad and confusing design.

@dhowe
Copy link

dhowe commented Jun 30, 2016

Agree ^

@Qkenkenu
Copy link

to start using NPM you need to initialize it for project you are developing,
use https://www.npmjs.com/package/initialize

br, Q

@psigen
Copy link

psigen commented Aug 19, 2016

Note that this warning also happens when installing packages outside any modules with a non-root user (at least on OSX).

~ $ npm install foobar
[...]
npm WARN ENOENT ENOENT: no such file or directory, open '/Users/[USERNAME]/package.json'
npm WARN EPACKAGEJSON [USERNAME] No description
npm WARN EPACKAGEJSON [USERNAME] No repository field.
npm WARN EPACKAGEJSON [USERNAME] No README data
npm WARN EPACKAGEJSON [USERNAME] No license field.

At the very least, this behavior seems pretty uninformative, and the above is not an unreasonable use case (as far as I can tell) for installing node-based CLI tools that are distributed by NPM as a non-root user.

@antics
Copy link

antics commented Aug 23, 2016

Fresh install on OSX 10.11.6 with node.js 6.4.0 Current:

Creator:qr antics$ npm install qrcode-reader
/Users/antics/Nodes/qr
└── qrcode-reader@0.2.1 

npm WARN enoent ENOENT: no such file or directory, open '/Users/antics/Nodes/qr/package.json'
npm WARN qr No description
npm WARN qr No repository field.
npm WARN qr No README data
npm WARN qr No license field.

@acarstoiu
Copy link

Please reopen this issue and eliminate these unjustified and annoying warnings.

@deepak040
Copy link

for remove these warnings from CLI when instaling it on magento local root then just check 2 files -
package.json.sample and Gruntfile.js.sample at magento root and try to rename them by removing .sample suffix and try again. i think now this issue being resolved

@asthagaur3
Copy link

i also get the same error but i am not able to remove it. give me any solution by which i can solve it

@deepak040
Copy link

deepak040 commented Sep 23, 2016

check your magento root directory and find these 2 files :
package.json.sample and Gruntfile.js.sample
then remove .sample from both files and try again i think its works now, otherwise comment your error here.i will try to solved it.

@asthagaur3
Copy link

magento is not in my aptop

@asthagaur3
Copy link

this is the error msg

npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Astha Gaur\package.json'
npm WARN Astha Gaur No description
npm WARN Astha Gaur No repository field.
npm WARN Astha Gaur No README data
npm WARN Astha Gaur No license field.

@pannous
Copy link

pannous commented Sep 23, 2016

solution to some use cases (not OP) : replace
sudo npm install with
sudo npm install -g

@fayeyen
Copy link

fayeyen commented Sep 24, 2016

thanks Qkenkenu!
"to start using NPM you need to initialize it for project you are developing,
use https://www.npmjs.com/package/initialize"

@asthagaur3
Copy link

i am using window

On Fri, Sep 23, 2016 at 5:53 PM, pannous notifications@github.com wrote:

solution to some use cases (not OP) : replace
sudo npm install with
sudo npm install -g


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#9161 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AVTyxVXzdH8C2MZzL0R2CfyH4ZyAQUI_ks5qs8TTgaJpZM4FlqO3
.

@RamMohan222
Copy link

I got this message while installing the newman and after that I'm checking the newman command it says

'newman' is not recognized as an internal or external command,
operable program or batch file.

npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\SUNKPOLP18\package.json'
npm WARN SUNKPOLP18 No description
npm WARN SUNKPOLP18 No repository field.
npm WARN SUNKPOLP18 No README data
npm WARN SUNKPOLP18 No license field.

@asthagaur3
Copy link

fristly run npm init command

then it will ask some question , you have give ask to all these .

On Thu, Sep 29, 2016 at 3:42 PM, RamMohan notifications@github.com wrote:

I got this message while installing the newman and after that I'm checking
the newman command it says

'newman' is not recognized as an internal or external command,
operable program or batch file.

npm WARN enoent ENOENT: no such file or directory, open
'C:\Users\SUNKPOLP18\package.json'
npm WARN SUNKPOLP18 No description
npm WARN SUNKPOLP18 No repository field.
npm WARN SUNKPOLP18 No README data
npm WARN SUNKPOLP18 No license field.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#9161 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AVTyxfg4YGNWdogHbRXrAStlBpCCVzi-ks5qu48egaJpZM4FlqO3
.

@TejashreeD
Copy link

TejashreeD commented Nov 15, 2016

This Works!
sudo npm install -g --save [package_name] or
npm install -g --save [package_name]

@tonybreak
Copy link

@TejashreeD this does work! thx a lot!

@acarstoiu
Copy link

My comment has seen so many votes, yet nobody from npm cares. And it's not the only comment that received public approval.

@othiym23, is it so difficult to admit that your way of thinking is not popular (to say the least) and fix this nonsense? Are you waiting for it to get even older than it already is (more than one year 👎 ) and then claim that "it's been working like this since forever"?

@legodude17
Copy link
Contributor

@acarstoiu please be more respectful. Also, the CLI team has a lot of work todo, as noted by the 2400+ open issues. Please be patient.

@legodude17
Copy link
Contributor

@acarstoiu, package.json is npm and nodejs's manifest file. Why would you need to install a module without package.json? The only one I think of is to just get the code, but that is what git clone is for. There is even a proposal for npm fetch, or a gist that I wrote.

@eush77
Copy link
Contributor Author

eush77 commented Nov 19, 2016

@legodude17

package.json is npm and nodejs's manifest file. Why would you need to install a module without package.json?

Node.js works without package.json just fine. It is a convenient feature for small projects that don't need to be packaged: small experiments, proofs of concepts, trying out to tie several modules' APIs together or just random hacking in the REPL. Creating package.json for such one-off use cases seems redundant.

@psigen
Copy link

psigen commented Nov 19, 2016

@legodude17 it is entirely reasonable to want to install one of the many CLI packages for node.

Doing npm install -g gulp should not result in an error if you don't happen to have a package.json in the current working directory where the command is run.

@kenany
Copy link
Contributor

kenany commented Nov 19, 2016

@psigen Fortunately that's exactly the behavior you'd see today when globally installing packages.

@legodude17
Copy link
Contributor

As @othiym23 said, you can just use npm init -y and then then the
package.json can help you with your messing around.

On Sat, Nov 19, 2016 at 11:35 AM, Eugene Sharygin notifications@github.com
wrote:

@legodude17 https://github.com/legodude17

package.json is npm and nodejs's manifest file. Why would you need to
install a module without package.json?

Node.js works without package.json just fine. It is a convenient feature
for small projects that don't need to be packaged: small experiments,
proofs of concepts, trying out to tie several modules' APIs together or
just random hacking in the REPL. Creating package.json for such one-off
use cases seems redundant.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9161 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AKr56HOKXkf1hHFXqiAfFixamcqS70Fgks5q_0-LgaJpZM4FlqO3
.

@acarstoiu
Copy link

For your information, Node.js works very well without any package.json, the only circumstance when this file helps is when a folder is require()d (namely, Node.js looks for the main property in package.json).

So, once again, a missing package.json is no reason for dummy warnings.

@legodude17
Copy link
Contributor

@acarstoiu I don't understand why you are so devoted to removing the warnings, when you could talk like a second to run npm init -y and then be on your merry way.

@Camwyn
Copy link

Camwyn commented Dec 1, 2016

I got here because of similar error messages but discovered it was because my editor had replaced all the spaces with tabs in package.json - so watch your package.json format!

@simonallison
Copy link

NPM professionalism...

@cvega
Copy link

cvega commented Jan 23, 2017

@legodude17 It feels like a hack to init a package when you are not in fact creating a package just to install other packages and suppress warnings? I just got bit by this in our build process, and it took me 20 minutes to track down. I'm happy to use the work around but I think @acarstoiu has a valid point even if the delivery of the message could have been better. Would we benefit from a cli switch to suppress warnings? I personally rather see this thrown as INFO before the package install starts versus doing the right thing then throwing a warning.

@scganterh
Copy link

As said, there are a lot of use cases where you are not creating a package. I'm writing a demonstration in which I have to use an NPM installable tool. Having a warning printed in a demonstration is very inconvenient, because you don't want to waste time explaining why it is there (which I frankly don't understand) and you also don't want to confuse your audience with workarounds.

@sparr
Copy link

sparr commented Mar 11, 2017

Chiming in alongside everyone else. I've just installed node and haven't started any projects yet. I do npm install something which seems quite happy to download versions to ~/.npm/something/x.x.x/ and ~/node_modules/something, but then it complains that ~/package.json doesn't exist and the other four warnings as well. This seems silly and misleading for an otherwise completely normal use case.

@timxor
Copy link

timxor commented Mar 16, 2017

+1 This is pretty annoying and unuseful error reporting. It would be cool if npm errors had hints to resolve the warning generated.

@legodude17
Copy link
Contributor

@sparr What is the use case for putting packages in your home directory? I have done that multiple times, every time it was a mistake, hence the warning.

@tcsiwula that would be a different issue.

@sparr
Copy link

sparr commented Mar 16, 2017

@legodude17 use case: I am not a Node module developer. I am just writing a five line node script without its own directory or npm init'd environment, and I need to install a dependency for it.

This is the equivalent of pip install without a python virtualenv environment, or gem install without a ruby rbenv environment, etc. Installing community libraries in my user's home directory is a perfectly normal thing to do in every language, apparently except for Node.

@legodude17
Copy link
Contributor

legodude17 commented Mar 16, 2017

If you think that is the best way, ok. IMHO it would be better to make that five line script into a module/package.

@sparr
Copy link

sparr commented Mar 16, 2017

@legodude17 YHO about what approach is better isn't relevant to the thousands of people who won't ever get involved with the node/npm community standards regarding module development, and just want to write a script and run it like they can in any other language

@sparr
Copy link

sparr commented Mar 16, 2017

Personally, my five line script is now 200 lines long, and I have done npm init to create a package.json... and npm still complains that I don't have a npm repository established and specified for my module.

@bartenbach
Copy link

+1 For these warnings being unhelpful and confusing

@equazcion
Copy link

equazcion commented Apr 7, 2017

I got this error when trying to install jquery.

I've never used Node.js before. Coming at this from the newbie's perspective, this is a noob-unfriendly warning. I'm trying to diagnose a problem and made the [quite natural] assumption that this might be the cause. It's the opposite of intuitive, and serves as a very efficient way of frustrating beginners away from pursuing work with Node.

If the existence of package.json is so "strongly preferred," why not at least make the warning more informative?

"Package.json is not required but is strongly preferred. Use [command] to create one for your project."

...so that we don't have to do google searches, then hopefully find this thread and have to read through several of its posts before finding the full explanation...?

@mhamzas
Copy link

mhamzas commented Apr 11, 2017

npm install -g --save [package_name]

This worked!

@Art4
Copy link

Art4 commented Apr 18, 2017

I got this error after I removed two unused packages (bower and grunt) with npm remove.

npm WARN enoent ENOENT: no such file or directory, open '[...]/node_modules/grunt/package.json'
npm WARN enoent ENOENT: no such file or directory, open '[...]/node_modules/bower/package.json'

Sure the package.json files don't exists. But who requested them??

Neither of the following tips had an effect:

  • sudo npm install -g npm
  • npm cache clean
  • npm prune

Finally I resolved this warning by deleting the whole node_modules folder and run npm install.

This warnings are useless if you don't know where they came from!

@itsmaheshkariya
Copy link

Even I got same problem...
just check your path firstly.....after that every thing will work correctly...

@shivamgupta-gupta
Copy link

There is one simple solution to this issue. Make sure that you are inside your project's directory when you run npm install.

@Art4
Copy link

Art4 commented May 26, 2017

Didn't work for me, see #9161 (comment)

@sparr
Copy link

sparr commented May 26, 2017

@shivamgupta-gupta you may have missed it up-thread, but many of us are not working in a node project directory.

@shivamgupta-gupta
Copy link

@sparr I haven't worked on complex projects but did you try this in your root directory?

@sparr
Copy link

sparr commented May 27, 2017

@shivamgupta-gupta Sorry if I was unclear. Some of us are not working on a thing that is a node project at all.

@jjc12
Copy link

jjc12 commented Jun 21, 2017

Voting to close the issue...@mhamzas npm install -g --save [package_name] worked.

From a StackOverflow answer:

npm install <package_name> without an option, just installs the package but does not update the dependencies as listed in your package.json.

npm install <package_name> --save installs the package and updates the dependencies in your package.json.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests