如何为项目指定本地版本的 Node?

How do I specify a local version of Node for a project?(如何为项目指定本地版本的 Node?)
本文介绍了如何为项目指定本地版本的 Node?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个项目,我们试图让 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)