How do I specify a local version of Node for a project?(如何为项目指定本地版本的 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),而不是在您尝试使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为项目指定本地版本的 Node?
基础教程推荐
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01