如何为项目指定本地版本的Node? [英] How do I specify a local version of Node for a project?

查看:71
本文介绍了如何为项目指定本地版本的Node?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我们试图在多个开发人员的计算机上启动并运行Node.问题在于,并非所有开发人员都是Node(甚至JavaScript)开发人员,我们希望确保他们具有运行特定项目所需的Node版本(开发人员在其计算机上将有多个Node项目).

I've got a project where we're trying to get Node up and running across multiple developers' machines. The problem is that not all of the developers are Node (or even JavaScript) developers, and we want to ensure that they have the Node version necessary to run a specific project (developers will have multiple Node projects on their machines).

我了解了package.json的"engines"字段,但似乎找不到任何方法来安装所需的Node版本.为了进行测试,我通过NVM将当前节点版本设置为v0.10.29,创建了一个package.json,指定了v0.11.13的必要引擎,并尝试通过 node 命令以及通过一个package.json定义的 npm start 命令.

I read about package.json's "engines" field, but I couldn't seem to find any way to get the version of Node installed that I needed. To test, I set my current node version to v0.10.29 via NVM, created a package.json specifying a necessary engine of v0.11.13, and tried to start Node via the node command as well as via a package.json-defined npm start command.

blackjack:node-engines-test sent1nel$ node -v
v0.10.29
blackjack:node-engines-test sent1nel$ cat package.json
{
  "name": "node-engines-test",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "engineStrict": true,
  "engines": {
    "node": "v0.11.13"
  },
  "start": "node index.js",
  "author": "",
  "license": "ISC"
}
blackjack:node-engines-test sent1nel$ cat index.js
console.log('Version: ' + process.version);
blackjack:node-engines-test sent1nel$ node index.js
Version: v0.10.29
blackjack:node-engines-test sent1nel$ npm start
blackjack:node-engines-test sent1nel$

npm install似乎也不在乎节点引擎版本.

npm install doesn't seem to care about the node engine version either.

blackjack:node-engines-test sent1nel$ npm install
npm WARN package.json node-engines-test@0.0.0 No description
npm WARN package.json node-engines-test@0.0.0 No repository field.
npm WARN package.json node-engines-test@0.0.0 No README data
blackjack:node-engines-test sent1nel$ node -v
v0.10.29

有什么用?!

推荐答案

我相信 engines engineStrict 适用于打包时已安装(通过npm),而不是在尝试通过节点执行时执行.这些选项会警告/阻止用户安装并非旨在与其当前使用的节点版本兼容(或兼容)的软件包.

I believe that the engines and engineStrict are for when the package is being installed (via npm), not when you're trying to execute something with node. These options warn/prevent users from installing a package that is not designed to work (or compatible) with the node version they are currently using.

这篇关于如何为项目指定本地版本的Node?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆