問題描述
我有一個項目,我們試圖讓 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),而不是在您嘗試使用 node.執行 某些東西時.這些選項警告/阻止用戶安裝不適合(或兼容)他們當前使用的節點版本的包.
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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!