https://www.wisdomgeek.com/development/web-development/javascript/how-to-prevent-npm-install-for-unsupported-node-js-versions/ * Home * Development * Self Help * About * Contact * Privacy Policy Sign in Welcome!Log into your account [ ]your username [ ]your password [LOG IN] Forgot your password? Privacy Policy Password recovery Recover your password [ ]your email [Send My Pass] Search [ ] WisdomGeek * Home * Development * Self Help * About * Contact * Privacy Policy WisdomGeek Facebook Instagram LinkedIn Twitter Youtube * Home * Development * Self Help * About * Contact * Privacy Policy More [ ] Search How to prevent npm install for unsupported Node.js versions [svg][e354decd32cf] By Saransh Kataria Modified date: March 17, 2022 Web DevelopmentJavaScript npm configurations allow us to do quite a lot of nifty things. One of them is to allow the project to set the Node.js version that needs to be used in order to run the project. This also provides us with the functionality to prevent npm install for unsupported Node.js versions. The engines property The engines property in the package.json can be used to define supported Node.js versions. It can accept a version range. - Advertisement - [INS::INS] { "engines": { "node": ">=0.10.3 <14" } } Specifying this property does not enforce the version. It only shows a warning when the user runs npm install on an unsupported Node.js version: $ npm install npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'wisdom-geek@1.0.0', npm WARN EBADENGINE required: { node: '<14.0.0' }, npm WARN EBADENGINE current: { node: 'v14.15.0', npm: '7.5.2' } npm WARN EBADENGINE } Stopping npm install with an unsupported Node.js version We need to create an npm configuration in the root directory of our project. You might know about this file as the .npmrc file. We then need to explicitly specify that we want to turn on engine checking for the project by using the key-value pair: engine-strict=true Once this is specified, and if someone tries to do an npm install on an unsupported Node.js version, they will get an error: npm install npm ERR! code EBADENGINE npm ERR! engine Unsupported engine npm ERR! engine Not compatible with your version of node/npm: wisdom-geek@1.0.0 npm ERR! notsup Not compatible with your version of node/npm: wisdom-geek@1.0.0 npm ERR! notsup Required: {"node":"<14.0.0"} npm ERR! notsup Actual: {"npm":"7.5.2","node":"v14.15.0"} How do I do this while using Yarn? Yarn does not need the .npmrc file and treats the engine property as strict by default. $ yarn install yarn install v1.22.5 info No lockfile found. [1/5] Validating package.json... error wisdom-geek@1.0.0: The engine "node" is incompatible with this module. Expected version "<14.0.0". Got "14.15.0" error Found incompatible module. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. And that is all it takes to prevent npm install for unsupported Node.js versions! * Tags * javascript * node * node.js Share Facebook Twitter Linkedin WhatsApp ReddIt Pinterest Email Previous articleHow to terminate a process on a port using the command line Recent Articles How to prevent npm install for unsupported Node.js versions JavaScript Saransh Kataria - Modified date: March 17, 2022 0 npm configurations allow us to do quite a lot of nifty things. One of them is to allow the project to set... Read more How to terminate a process on a port using the command line Development Saransh Kataria - Modified date: March 10, 2022 0 Zombie processes are usually a pain to figure out. More often than not, I end up googling about how to terminate a... Read more Detecting dark mode preference using JavaScript JavaScript Saransh Kataria - Modified date: March 2, 2022 0 As dark themes have become popular across the web and across operating systems, we might want to check the user's operating system... Read more JavaScript: Split string and keep the separators JavaScript Saransh Kataria - Modified date: February 1, 2022 0 String.prototype.split() is a valuable method to split strings based on a delimiter. There often comes a scenario when we want to split... Read more Printing JavaScript stack traces using console.trace JavaScript Saransh Kataria - Modified date: January 26, 2022 0 The console object in JavaScript has a lot more useful functions than the most frequently used console.log method. Debugging errors and finding... Read more Related Stories JavaScript Detecting dark mode preference using JavaScript Saransh Kataria - Modified date: March 2, 2022 0 As dark themes have become popular across the web and across operating systems, we might want to check the user's operating system... Read more JavaScript JavaScript: Split string and keep the separators Saransh Kataria - Modified date: February 1, 2022 0 String.prototype.split() is a valuable method to split strings based on a delimiter. There often comes a scenario when we want to split... Read more JavaScript Printing JavaScript stack traces using console.trace Saransh Kataria - Modified date: January 26, 2022 0 The console object in JavaScript has a lot more useful functions than the most frequently used console.log method. Debugging errors and finding... Read more JavaScript Overriding nested dependencies in NPM Saransh Kataria - Modified date: January 18, 2022 0 Whenever we install a particular package, it is common to come across a problem with a dependency's dependency. With the release of... Read more JavaScript Flatten Arrays in Vanilla JavaScript with flat() and flatMap() Saransh Kataria - Modified date: January 5, 2022 0 ES2019 introduced two methods on the array prototype that would make life so much simpler for developers. These are flat() and flatmap ()... Read more JavaScript Using GroupBy on an array of objects in JavaScript Saransh Kataria - Modified date: December 29, 2021 0 Array grouping is a fairly common operation in any project. Until recently, we had to resort to either writing our own implementation... Read more Leave A Reply Cancel reply [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] Please enter your comment! [ ] Please enter your name here [ ] You have entered an incorrect email address! Please enter your email address here [ ] [ ] Save my name, email, and website in this browser for the next time I comment. [Post Comment] [gif][tdn_pic_3] Hi there! Want some more knowledge? Think that the knowledge shared is helpful? You might want to give our mailing list a try. We'll send you 2-4 emails a month, right when new posts come out. [ ] Subscribe * Home * Development * Self Help * About * Contact * Privacy Policy (c) Wisdom Geek. All Rights Reserved. Close this module newsletternewsletter Hi there! Want some more knowledge? Think that the knowledge shared is helpful? You might want to give our mailing list a try. We'll send you 2-4 emails a month, right when new posts come out. Enter your email[ ]Enter your email Sign me up! NO THANKS Add Wisdom Geek to your Homescreen! Add