强制删除npm_如何强制使用纱线或NPM
强制删除npm
In this short post, I’m going to show you how to prevent the usage of npm or yarn, depending on your needs. Let’s get started!
在这篇简短的文章中,我将向您展示如何根据需要防止使用npm或yarn 。 让我们开始吧!
编辑.npmrc (Edit .npmrc)
You might not have this file in your codebase. If this is the case, create this file in the root folder of your application.
您的代码库中可能没有此文件。 在这种情况下,请在应用程序的根文件夹中创建此文件。
It allows us to specify package manager configurations and it is used by both npm and yarn.
它允许我们指定程序包管理器配置, npm和yarn都使用它。
Your
.npmrcfile should have the
engine-strictproperty marked as
true.
您的
.npmrc文件应将
engine-strict属性标记为
true。
//.npmrc file engine-strict = true
This option tells the package manager to use the version of the engines we have specified in the
package.jsonfile.
此选项告诉程序包管理器使用我们在
package.json文件中指定的引擎版本。
编辑package.json (Edit package.json)
Inside your
package.jsonfile you should add the
enginessection if you don’t currently have it.
如果没有,请在
package.json文件中添加
engines部分。
//package.json { ... "engines": { "npm": "please-use-yarn", "yarn": ">= 1.19.1" }, ... }
In the above code, the
package.jsonfile uses a version of
yarn1.19.1 or greater.But for
npmwe specify a version that doesn’t exist.
在上面的代码中,
package.json文件使用的是
yarn1.19.1或更高版本,但是对于
npm我们指定了一个不存在的版本。
This way we make sure that when someone tries to use
npminstead of
yarn, they will receive an error that outputs ‘
please-use-yarn‘.
这样,我们可以确保当有人尝试使用
npm而不是
yarn,他们将收到输出“
please-use-yarn”的错误。
运行npm install (Running npm install)
Once you’ve done the above changes, try to run
npm install.
完成上述更改后,尝试运行
npm install。
You will receive an error that prevents you from using
npm.
您将收到一条错误消息,阻止您使用
npm。
npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for my-app@0.1.0: wanted: {"npm":"please-use-yarn","yarn":">= 1.19.1"} (current: {"node":"12.16.3","npm":"6.14.4"}) npm ERR! notsup Not compatible with your version of node/npm: my-app@0.1.0 npm ERR! notsup Not compatible with your version of node/npm: my-app@0.1.0 npm ERR! notsup Required: {"npm":"please-use-yarn","yarn":">= 1.19.1"} npm ERR! notsup Actual: {"npm":"6.14.4","node":"12.16.3"} npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\YourUser\AppData\Roaming\npm-cache\_logs\2020-05-21T10_21_04_676Z-debug.log
This, of course, can be done the other way around if you want to prevent the usage of
yarn.
当然,如果要防止使用
yarn,也可以采用其他方法。
结论 (Conclusion)
It is pretty straightforward and easy to ensure that only one package manager must be used inside your project.This will reduce the chance of errors caused by developers that are using different package managers and it is a good practice to standardize the project’s coding rules and management.
确保在项目内部仅使用一个软件包管理器非常简单明了,这将减少使用不同软件包管理器的开发人员导致的错误机会,并且是标准化项目编码规则和管理的良好实践。
You can reach out and ask me anything on Twitter, Facebook and my website.
您可以在Twitter , Facebook和我的网站上向我提问。
翻译自: https://www.freecodecamp.org/news/how-to-force-use-yarn-or-npm/
强制删除npm
- 如何自如地使用npm在项目中安装、删除模块包
- 如何强制删除或恢复SQLServer正在使用的数据库
- 如何强制删除或恢复SQLServer正在使用的数据库
- 如何强制删除正在使用的文件
- 如何强制删除或恢复SQLServer正在使用的数据库
- Linux Shell - 如何使用sort与uniq命令删除重复的文本行
- 如何强制不使用科学计数法
- 如何使用UltraEdit去删除含有特写字符的行?
- 使用VS2005中的GridView中的CommandField进行删除操作时,如何弹出确认对话框?
- ABAP--如何使用REUSE_ALV_GRID_DISPLAY函数删除内表数据(样例代码,感谢依风提供)
- 如何使用dw的查找功能,删除所有的链接即标签?
- 如何查看/删除使用WANem或者其它时候的网关设置
- 如何删除std::vector内的element?(使用for loop) (中级)
- ABAP--如何使用REUSE_ALV_GRID_DISPLAY函数删除内表数据(样例代码,感谢依风提供)
- 如何防止别人使用、更改或删除电脑里的重要资料?
- 如何使用谷歌的网页删除请求工具?
- 如何使用CommandArgument属性根据id删除记录
- 如何手动强制删除Exchange 2003
- 如何使用Java操作LDAP之删除条目(四)
- LINQ to SQL 系列 如何使用LINQ to SQL插入、修改、删除数据