Javascript 如何让纱线不对许可证字段发出警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45690202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to have yarn not issue a warning for the license field?
提问by k0pernikus
On running yarn installI see a warning every time that there is no license filed even though I have defined one:
在运行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"
}
}
which according to the npm defintionshould be valid:
根据npm 定义,它应该是有效的:
Finally, if you do not wish to grant others the right to use a private or unpublished package under any terms:
{ "license": "UNLICENSED" }
最后,如果您不希望根据任何条款授予他人使用私有或未发布包的权利:
{ "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?
如何在不出现警告的情况下将纱线项目标记为专有?
回答by k0pernikus
For yarnand npm, the default behavior is that they look up into the parent directories.
对于yarnand npm,默认行为是它们查找父目录。
I had an outdated and forgotten package.jsonin my home folder without a license field:
我的package.json主文件夹中没有许可证字段,但已过时且被遗忘:
~/package.json
When running yarn installwithin my project:
yarn install在我的项目中运行时:
~/my-project/package.json
yarnthen also found the one in my home directory and reported the error for that one. I mistook that for my project's package.json.
yarn然后也在我的主目录中找到了那个并报告了那个错误。我误认为是我的项目的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.jsonI get the expected output:
删除过时的内容后,package.json我得到了预期的输出:
yarn install v0.27.5
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.88s.
回答by Shailesh kala
I got stuck in the same error and I found that when we add package.jsonor 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.
我陷入了同样的错误,我发现当我们添加package.jsonor 时yarn,系统根目录中可能存在一些文件。因此,错误来自系统根目录。您可以简单地删除这些文件,错误将不再存在。
- just cd ~, then you can find package.json & yarn.lock.
- rm -rf package.json or rm -rf yarn.lock
- 只要 cd ~,然后你就可以找到 package.json 和 yarn.lock。
- rm -rf package.json 或 rm -rf yarn.lock
回答by Larry DaBig Meech
Just make sure you are in the directory that contains the package.json file, then just yarnor npminstall then serveit as you please.
只要确保你是在包含的package.json文件的目录,然后就纱或NPM安装则成为它,你请。
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:
此外,请参阅有关运行包所需的必填字段的更多信息以及有关带有yarn/npm的 package.json 文件的其他提示:
https://classic.yarnpkg.com/en/docs/package-json/
https://docs.npmjs.com/files/package.json
回答by Keet Sugathadasa
I was getting the following warning along with some other licensing warnings.
我收到以下警告以及其他一些许可警告。
warning package.json: No license field
warning [email protected]: No license field
All I did was, update the package.jsonfile's privateproperty to be true.
我所做的只是将package.json文件的private属性更新为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 fieldwarnings when I do yarn install. To understand why, please see this question.
有了这个,No license field当我这样做时,我不再收到任何警告yarn install。要了解原因,请参阅此问题。
{"private": true}means, that npm will refuse to publish it, to prevent accidental publication of private repositories.
{"private": true}意味着,npm 将拒绝发布它,以防止意外发布私有存储库。
For more on this, see the following links. https://docs.npmjs.com/files/package.json#privatehttps://flaviocopes.com/package-json/#private
有关这方面的更多信息,请参阅以下链接。 https://docs.npmjs.com/files/package.json#private https://flaviocopes.com/package-json/#private

