javascript - 为什么当我指示更高版本的 NodeJS 时 "npm install"没有失败?

标签 javascript node.js npm node-modules

我想在我的 NodeJS 项目中强制执行 NodeJS 和 NPM 的确切版本。这是我的 package.json:

{
  "name": "nodesandbox",
  "version": "0.0.1",
  "dependencies": {
    "less": "*"
  },
  "engines": {
    "node": "0.10.25"
  }
}

当我运行 nvm ls 时,我得到了这个输出:

    v0.2.6
    v0.7.12
    v0.9.6
  v0.10.12
  v0.10.15
  v0.10.21
current:    v0.10.24

当我运行 npm install 时它工作正常,但我希望它失败。我已按照此链接 [1] 中的说明进行操作,这就是为什么我认为在引擎对象中设置 Node 版本应该有效,但遗憾的是它不起作用。

[1] http://blog.nodejitsu.com/package-dependencies-done-right/#node-dependency-in-apps

最佳答案

它看起来像 engine仅当从另一个位置获取包时才会检查依赖项:

[timwolla@/tmp/test2]npm install ../test
npm WARN engine nodesandbox@0.0.1: wanted: {"node":"0.10.30"} (current: {"node":"v0.10.26","npm":"1.4.3"})

如果engineStrict设置为真:

[timwolla@/tmp/test2]npm install ../test
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your version of node/npm: nodesandbox@0.0.1
npm ERR! notsup Required: {"node":"0.10.30"}
npm ERR! notsup Actual:   {"npm":"1.4.3","node":"v0.10.26"}

如果您阅读 the manual仔细看看为什么会很清楚(实际上我不是 100% 确定):

比较

npm install (in package directory, no arguments):

Install the dependencies in the local node_modules folder.

npm install <folder>:

Install a package that is sitting in a folder on the filesystem.

第一个声明安装依赖项,第二个声明安装

关于javascript - 为什么当我指示更高版本的 NodeJS 时 "npm install"没有失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22418156/

相关文章:

node.js - 我如何依赖 meteor 应用程序中的版本过期的 npm 包?

javascript - Jquery异步调用按顺序

javascript - 递归 JavaScript Promise 的正确链接

javascript - 如何将传递给 Nodejs 的查询字符串转发到通过 res.render 提供服务的页面?

javascript - Hapi-Joi 验证有效负载可以是对象数组还是简单的 Javascript 对象?

javascript - Node - 运行全局安装的自定义模块

node.js - 使用 webpack 打包库时 lib 和 dist 文件夹之间的区别?

javascript - 使用 CSS 网格,从任何地方滚动一个 div(不使用 jQuery 插件)

javascript - 如何使用react-native显示/隐藏内容?

mysql - 如何在插入数据之前检查nodejs中的mysql表字段类型