919

I installed Express.js with the following command:

sudo npm install -g express

I get the following warnings:

npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No readme data.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.

Why do I have the above warnings? Should I be worried?

3
  • 25
    By seeing this question one year later, I realize that I mentally erase all these warnings every time I install npm packages. This is something package developers should maybe be a bit more careful about.
    – nha
    Sep 27, 2014 at 11:53
  • @nha yeah, I usually see those warnings when doing some npm operation and fix them if it's in the package I'm developing. Oct 17, 2014 at 3:40
  • 40
    for private repos, just add "private": true to package.json
    – chovy
    Nov 29, 2015 at 10:05

12 Answers 12

1402

It's just a check as of NPM v1.2.20, they report this as a warning.

However, don't worry, there are sooooooo many packages which still don't have the repository field in their package.json. The field is used for informational purposes.

In the case you're a package author, put the repository in your package.json, like this:

"repository": {
  "type": "git",
  "url": "git://github.com/username/repository.git"
}

Read more about the repository field, and see the logged bug for further details.


Additionally, as originally reported by @dan_nl, you can set private key in your package.json.
This will not only stop you from accidentally running npm publish in your app, but will also stop NPM from printing warnings regarding package.json problems.

{
  "name": "my-super-amazing-app",
  "version": "1.0.0",
  "private": true
}
8
  • 21
    A few months after my answer and I haven't seem any problems so far :) Sep 1, 2013 at 23:28
  • 4
    NPM 2.14 now does print an error when repository is empty and private is set to true.
    – Blaise
    Oct 8, 2015 at 9:01
  • 9
    @Blaise, I don't get any warnings in NPM 3.3.3 by using private: true Jan 6, 2016 at 10:50
  • 4
    Question, why isnt "private" the default, I mean how many npm projects are created versus how many are actually published, is there really more library code than user code?
    – Felype
    Oct 30, 2017 at 2:35
  • The documentation you linked does not explain why the field is required just that it is useful. Technically, it isn't required (warning vs. error) but I am sure someone is going to wonder why the tool cares at all. Feb 4, 2018 at 20:58
411

You can also mark the application as private if you don’t plan to put it in an actual repository.

{
  "name": "my-application",
  "version": "0.0.1",
  "private": true
}
0
56

As dan_nl stated, you can add a private fake repository in package.json. You don't even need name and version for it:

{
  ...,
  "repository": {
    "private": true
  }
}

Update: This feature is undocumented and might not work. Choose the following option.

Better still: Set the private flag directly. This way npm doesn't ask for a README file either:

{
  "name": ...,
  "description": ...,
  "version": ...,
  "private": true
}
4
  • 1
    Got notified about another user about this answer. Looks like repository.private is not documented behaviour (or it is no longer accepted), according to docs.npmjs.com/files/package.json. Sep 2, 2018 at 14:06
  • 1
    @gustavohenke: Thank you, it seems you're right - private as top-level property is the better option anyway. Updated my answer.
    – wortwart
    Sep 3, 2018 at 19:24
  • "Set the private flag directly" - this doesn't work for me, I had to specify the private flag inside a "repository" section. Npm version 9.6.7
    – rayzinnz
    Nov 21, 2023 at 0:08
  • Surprising -- the private property is the official way also in v9 (docs.npmjs.com/cli/v9/configuring-npm/package-json#private) while repository.private is undocumented and may or (probably) may not work.
    – wortwart
    Nov 28, 2023 at 16:56
48

If you are getting this from your own package.json, just add the repository field to it. (use the link to your actual repository):

"repository" : { 
  "type" : "git",
  "url" : "https://github.com/npm/npm.git"
}
1
  • Thanks for clarifying to use the full github project file link (including http:// or https://!
    – twk
    Feb 22, 2017 at 12:15
9

Have you run npm init? That command runs you through everything...

8

In Simple word- package.json of your project has not property of repository you must have to add it,

and you have to add repository in your package.json like below

enter image description here

and Let me explain according to your scenario

you must have to add repository field something like below

  "repository" : {     
     "type" : "git",
      "url" : "http://github.com/npm/express.git" 
   }
0
7

If you don't want to specify a repository you can add the following lines to the package.json file:

"description":"",
"version":"0.0.1",
"private":true,

That worked for me.
By adding private, you don't need to link to a repo.

7

To avoid warnings like:

npm WARN [email protected] No repository field.

You must define repository in your project package.json. In the case when you are developing with no publishing to the repository you can set "private": true in package.json

Example:

{
  "name": "test.loc",
  "version": "1.0.0",
  "private": true,
  ...
  "license": "ISC"
}

NPM documentation about this: https://docs.npmjs.com/files/package.json

4

this will help all of you to find your own correct details use

npm ls dist-tag

this will then show the correct info so you don't guess the version file location etc

enjoy :)

1
  • 1
    I got a response as '--empty
    – M.J
    Jul 27, 2019 at 18:27
3

Yes, probably you can re/create one by including -f at the end of your command

0

Try: npm install package.json, npm audit fix --force, ncu -u

-1

use npm install -g angular-cli instead of
npm install -g@nagular/cli to install Angular

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.