如何让纱线不对牌照领域发出警告?

在运行 yarn install时,我每次看到一个警告,即使我已经定义了一个许可证,但是没有提交任何许可证:

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

根据 Npm 定义的规定,它应该是有效的:

最后,如果您不希望授予他人使用私有 或未出版的包装:

{ "license": "UNLICENSED" }

输出如下:

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.

我的主要目标是让这个警告消失,但是我也不想提供一个无效的开源许可证来使这个警告消失,即使它是一个内部项目,从来不会在外面看到。

如何在不出现警告的情况下将纱线项目标记为专有?

108887 次浏览

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.

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

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

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

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

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 ;-)

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

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.