Prevent npm install for not supported Node.js versions (#tilPost)

Yesterday I was reviewing a pull request to Contentful’s Gatsby starter and learned a nifty little detail about npm configurations.
The goal of his pull request was to guarantee that people setting up the project use a specific Node…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Yesterday I was reviewing a pull request to Contentful's Gatsby starter and learned a nifty little detail about npm configurations.

The goal of his pull request was to guarantee that people setting up the project use a specific Node.js version. You can define the engines property in your package.son to specify a version range.

{
  "engines": {
    "node": ">=12.0.0"
  }
}

A lot of projects define the property, but so far, I've never seen more than a little warning popping up when you run npm install. It turns out you can add a local npm configuration file (.npmrc) to your module/project root and explicitly turn on strict engine handling.

engine-strict=true

With this .npmrc in the project root, people are not able to run npm install if their Node.js is not fulfilling your requirements. ?

npm install
npm ERR! code ENOTSUP
npm ERR! notsup Unsupported engine for my-node-project@1.0.0: wanted: {"node":">=12.0"} (current: {"node":"10.20.1","npm":"6.14.4"})

FAIL 1

What about Yarn? Yarn doesn't need an additional configuration file and treats the engines property strictly by default.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2020-05-20T22:00:00+00:00) Prevent npm install for not supported Node.js versions (#tilPost). Retrieved from https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/

MLA
" » Prevent npm install for not supported Node.js versions (#tilPost)." Stefan Judis | Sciencx - Wednesday May 20, 2020, https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/
HARVARD
Stefan Judis | Sciencx Wednesday May 20, 2020 » Prevent npm install for not supported Node.js versions (#tilPost)., viewed ,<https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » Prevent npm install for not supported Node.js versions (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/
CHICAGO
" » Prevent npm install for not supported Node.js versions (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/
IEEE
" » Prevent npm install for not supported Node.js versions (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/. [Accessed: ]
rf:citation
» Prevent npm install for not supported Node.js versions (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2020/05/20/prevent-npm-install-for-not-supported-node-js-versions-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.