I have a Node.js project that requires Node version 12 or higher. Is there a way to specify this in the packages.json file, so that the installer will automatically check and inform the users if they need to upgrade?
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- Failed at the electron@1.8.2 postinstall script
- How to reimport module with ES6 import
- Webpack getting started, import error
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
- Get file created date in node
Add
to
package.json
to the file
.npmrc
(close topackage.json
, same directory)Just like said Ibam,
engineStrict
is now deprecated. But I've found this solution:check-version.js:
package.json:
Find out more here: https://medium.com/@adambisek/how-to-check-minimum-required-node-js-version-4a78a8855a0f#.3oslqmig4
.nvmrc
And one more thing... A dotfile '.nvmrc' can be used for requiring specific node version (but I didn't try it yet) - https://github.com/creationix/nvm#nvmrc
I think you can use the "engines" field:
As you're saying your code definitely won't work with any lower versions, you probably want the "engineStrict" flag too:
Documentation for the package.json file can be found on the npmjs site
Update
engineStrict
is now deprecated, so this will only give a warning. It's now down to the user to runnpm config set engine-strict true
if they want this.There's another, simpler way to do this:
npm install Node@8
(saves Node 8 as dependency in package.json)This works because
node
is just a package that ships node as its package binary. It just includes as node_module/.bin which means it only makes node available to package scripts. Not main shell.See discussion on Twitter here: https://twitter.com/housecor/status/962347301456015360