109

On running yarn install I see a warning every time that there is no license filed even though I have defined one:

$ jq . package.json 
{
  "name": "license-example",
  "version": "1.0.0",
  "main": "index.js",
  "license": "UNLICENSED",
  "dependencies": {
    "lodash": "^4.17.4",
    "moment": "^2.18.1"
  }
}

which according to the npm defintion should be valid:

Finally, if you do not wish to grant others the right to use a private or unpublished package under any terms:

{ "license": "UNLICENSED" }

Here's the output:

yarn install
yarn install v0.27.5
warning ../package.json: No license field
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.09s.

My main goal is for that warning to disappear, yet I also don't want to provide an invalid open-source LICENSE to make the warning go away, even if it is an internal project that never will be seen on the outside.

How to mark a yarn project as proprietary without a warning appearing?

Keet Sugathadasa
  • 11,595
  • 6
  • 65
  • 80
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • 8
    Weird. Don't see how it could happen, if it is configured properly. yarn basically checks it it is a string: https://github.com/yarnpkg/yarn/blob/e177c3732e6cd2adb468427d06a3bbcd2a5e4356/src/util/normalize-manifest/validate.js#L78 Try to set `{"private": true}` to skip the check entirely. – Alex Blex Aug 15 '17 at 09:45
  • I don't think it's `.license`. It's `LICENSE` - all caps, no extension. – Andy Aug 15 '17 at 09:48
  • Double checked, and couldn't reproduce. Is the any chance to get a made-up package.json that reproduces the problem? – Alex Blex Aug 15 '17 at 10:19
  • @AlexBlex I just generated a example project, same behavior. See updated question for package.json. I'm on Ubuntu by the way, can this may be a bug related to the OS? – k0pernikus Aug 15 '17 at 10:25
  • tested on 16.04 with the package from the question. No warnings: `node_modules/.bin/yarn install \n yarn install v0.27.5 \n [1/4] Resolving packages... \n success Already up-to-date. \n Done in 0.28s. \n ` – Alex Blex Aug 15 '17 at 10:35
  • @AlexBlex Thank you for your feedback. It made me look at the problem from a different angle, and I found the solution. I've added it as an answer. – k0pernikus Aug 15 '17 at 11:01
  • The question solved my problem! You get a +1 for that. – Sam Watkins Oct 11 '21 at 17:25
  • I think "PROPRIETARY" would be slightly better than using "UNLICENSED". This site (https://cpl.thalesgroup.com/software-monetization/proprietary-software-license#:~:text=A%20proprietary%20license%20model%20is,Photoshop%2C%20Skype%2C%20and%20more.) has a good description of a PROPRIETARY license: A proprietary license model is based on the concept that the software company creates software and maintains control over its code, and therefore, its features and use. – ScottD Aug 25 '22 at 12:44

9 Answers9

217

For yarn and npm, the default behavior is that they look up into the parent directories.

I had an outdated and forgotten package.json in my home folder without a license field:

~/package.json

When running yarn install within my project:

~/my-project/package.json

yarn then also found the one in my home directory and reported the error for that one. I mistook that for my project's package.json.

The warning makes that clear by preceding the path with .. for the parent folder.

warning ../package.json: No license field

After removing that outdated package.json I get the expected output:

yarn install v0.27.5
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.88s.
Keet Sugathadasa
  • 11,595
  • 6
  • 65
  • 80
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • 5
    Very helpful! It keeps me puzzled whether people writing those warnings really hate their job... why not simply write a more clear warming like "warning ../package.json **in a parent directory**: No license field"? – Dmitri Zaitsev May 24 '19 at 01:59
  • 5
    Hah, related: I had this warning every time I opened a shell, turns out I had a `package.json` after executing yarn in my home folder (because `cd` is hard). Thanks for the answer! – Kyll Jun 18 '19 at 18:36
  • It works! But isn't this dangerous? After all, if you have a typo and type "UNLICENSE", your whole code will be in the public domain! Isn't there a more failsafe expression than "UNLICENSED"? – morgler May 01 '20 at 09:25
  • 2
    Thanks for this, I had package.json in my home directory and that's why I was getting the warning. – Marcin Nabiałek May 11 '20 at 07:03
  • 2
    Adding `"private": true` to the `package.json` file is the correct way to prevent this warning, in a typical case where your software is proprietary and not meant to be licensed to the public or published. The accepted answer is a pretty extreme edge case. See other answers below. – Andrew Koster Jun 08 '20 at 22:41
  • It might be an edge case @AndrewKoster but I had the same issue although more like ../../../../../../ and the local package did have the private set to true? – Ray Oei Jan 23 '21 at 22:04
  • I had a `package.json` and `package-lock.json` on my `/home` dir, deleting those solves the problem. - Ubuntu user – U.A May 26 '21 at 12:49
42

Take a closer look at the message:

warning ../package.json: No license field

It's referring to a package.json one directory level higher.
Fix that one by either entering a license field or a private: true or delete it because it probably should not be there anyway ;-)

Ali80
  • 6,333
  • 2
  • 43
  • 33
Gernot Ullrich
  • 647
  • 6
  • 7
  • 1
    Yes, I got a `package.json` a directory higher. After deleting it the warning was gone. – A.W. Jul 19 '21 at 04:40
  • 5
    Wow. Thank you. I wasn't paying attention. Mine was ../../package.json. Why on earth is yarn walking UP the directory tree two levels? That seems like very strange behavior since I have a package.json in the same folder I ran the command from. – DustinA Oct 09 '21 at 16:53
  • 3
    I had a tiny `package.json` for some reason in my home directory. I've been living with this warning for years. Thanks! – Daniel Darabos Feb 02 '23 at 16:03
30

I was getting the following warning along with some other licensing warnings.

warning package.json: No license field
warning react-material-dashboard@0.3.0: No license field

All I did was, update the package.json file's private property to be true.

{
  "name": "some-application-name",
  "author": "Keet Sugathadasa",
  "email": "email",
  "license": "MIT",
  "version": "0.0.1",
  "private": true,
  ...
}

With this, I no longer got any No license field warnings when I do yarn install. To understand why, please see this question.

{"private": true} means, that npm will refuse to publish it, to prevent accidental publication of private repositories.

For more on this, see the following links. https://docs.npmjs.com/files/package.json#private https://flaviocopes.com/package-json/#private

Keet Sugathadasa
  • 11,595
  • 6
  • 65
  • 80
18

After trying multiple solutions, i found there were following files in root, need to delete:

cd ~
~$ rm -rf package.json
~$ rm -rf yarn.lock
~$ rm -rf package-lock.json
Tahir Abbas
  • 181
  • 1
  • 2
  • To clarify, @Tahir is deleting `package.json` files not associated with any project, as mentioned in [Gernot's answer](https://stackoverflow.com/a/64956962/2430657). You should not run these commands if your project happens to be in your home directory (which is not a recommended place to put your project). – Alexander May 27 '22 at 23:05
8

I am new to the react, but I find, the most simplest way is: just add the "private": true, to your package.json file. That's it.

Danson
  • 121
  • 1
  • 5
7

I got stuck in the same error and I found that when we add package.json or yarn, some files can be there in the system roots. So, the errors are from there the system root. You can simply remove those files and the error will not be there anymore.

  1. just cd ~, then you can find package.json & yarn.lock.
  2. rm -rf package.json or rm -rf yarn.lock
Keet Sugathadasa
  • 11,595
  • 6
  • 65
  • 80
Shailesh kala
  • 1,618
  • 18
  • 16
0

If the error persists, just check your system root at C:\Users\User you will see a package.json and yarn.lock files, delete them, the warning will go. These are the files interfering with your project

  • OP isn't necessarily on Window OS, so your answer should target other OS, too. Furthermore, although your suggestion is good - it doesn't always work – Tzahi Leh Aug 24 '23 at 08:21
-2

Just make sure you are in the directory that contains the package.json file, then just yarn or npm install then serve it as you please.

I am currently running a project without the license field and it works perfectly, I don't think that can return an error.

Also, see more information regarding the mandatory fields you need for your package to run and other tips regarding the package.json file with yarn/npm:

https://classic.yarnpkg.com/en/docs/package-json/

https://docs.npmjs.com/files/package.json
-3

I had similar issue, i just upgraded the version of Node and every thing worked fine.....

Sybghat
  • 1
  • 3
  • Hi Sybghat. Could you explain what version had the issue and what you updated to? – Glitcher Jun 03 '21 at 11:30
  • 1
    i had version 8 and updated it to 10 I followed Following Steps: 1- sudo apt install curl 2- curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - 3- sudo apt install nodejs – Sybghat Jun 03 '21 at 12:14
  • I've moved your comment into the answer. Please feel free to edit it however you think best :) – Glitcher Jun 04 '21 at 13:17