博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
强制删除npm_如何强制使用纱线或NPM
阅读量:2527 次
发布时间:2019-05-11

本文共 2837 字,大约阅读时间需要 9 分钟。

强制删除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!

在这篇简短的文章中,我将向您展示如何根据需要防止使用npmyarn 。 让我们开始吧!

编辑.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.

它允许我们指定程序包管理器配置, npmyarn都使用它。

Your .npmrc file should have the engine-strict property marked as true.

您的.npmrc文件应将engine-strict属性标记为true

//.npmrc fileengine-strict = true

This option tells the package manager to use the version of the engines we have specified in the package.json file.

此选项告诉程序包管理器使用我们在package.json文件中指定的引擎版本。

编辑package.json (Edit package.json)

Inside your package.json file you should add the engines section 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.json file uses a version of yarn 1.19.1 or greater.But for npm we specify a version that doesn’t exist.

在上面的代码中, package.json文件使用的是yarn 1.19.1或更高版本,但是对于npm我们指定了一个不存在的版本。

This way we make sure that when someone tries to use npm instead 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 ENOTSUPnpm 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.0npm ERR! notsup Not compatible with your version of node/npm: my-app@0.1.0npm 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 , and my .

您可以在 , 和我的上向我提问。

翻译自:

强制删除npm

转载地址:http://zlgwd.baihongyu.com/

你可能感兴趣的文章
什么是blob,mysql blob大小配置介绍
查看>>
模运算的规则
查看>>
CSS样式布局入门介绍,非常详尽
查看>>
android app崩溃日志收集以及上传
查看>>
3、VS2010+ASP.NET MVC4+EF4+JqueryEasyUI+Oracle项目开发之——用户登录
查看>>
面试记-(1)
查看>>
压力测试 相关
查看>>
android update automatically ( android 自动升级)
查看>>
session cookie
查看>>
POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)
查看>>
【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
查看>>
几种简单的负载均衡算法及其Java代码实现
查看>>
TMS3705A PCF7991AT 线路图
查看>>
白盒测试实践(小组作业)day4
查看>>
为什么学sail.js
查看>>
pythen创建cocos2dx项目
查看>>
js调用.net后台事件,和后台调用前台等方法总结
查看>>
Vert.x 之 HelloWorld
查看>>
太阳能路灯项目背景知识
查看>>
Objec类和final关键字的用法
查看>>