99

I had to change the version of my npm app from 0.1 to 0.0.1 in order for npm not to do this.

$ npm install
npm ERR! install Couldn't read dependencies
npm ERR! Error: invalid version: 0.1
npm ERR!     at validVersion (/usr/local/Cellar/node/0.10.5/lib/node_modules/npm/node_modul
es/read-package-json/read-json.js:571:40)
npm ERR!     at final (/usr/local/Cellar/node/0.10.5/lib/node_modules/npm/node_modules/read
-package-json/read-json.js:323:23)
npm ERR!     at /usr/local/Cellar/node/0.10.5/lib/node_modules/npm/node_modules/read-packag
e-json/read-json.js:139:33
npm ERR!     at cb (/usr/local/Cellar/node/0.10.5/lib/node_modules/npm/node_modules/slide/l
ib/async-map.js:48:11)
npm ERR!     at /usr/local/Cellar/node/0.10.5/lib/node_modules/npm/node_modules/read-packag
e-json/read-json.js:301:48
npm ERR!     at fs.js:207:20
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Darwin 12.3.0
npm ERR! command "/usr/local/Cellar/node/0.10.5/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/lust/Documents/ply/dev-server
npm ERR! node -v v0.10.5
npm ERR! npm -v 1.2.18
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/lust/Documents/ply/dev-server/npm-debug.log
npm ERR! not ok code 0

For completeness here's the working json

$ cat package.json
{
    "name": "ply",
    "description": "ply server for local dev testing deployments",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "express": "3.x"
    }
} 

version used to be "0.1" when it made the error.

Is this some sort of API/ABI compatibility versioning concept requiring 3 sets of version numbers? Why is the error message not more friendly w.r.t. this?

4

3 回答 3

117

是的,这是语义版本控制所必需的,这是 npm 包使用的版本控制方案。这是来自的片段npm help json

版本必须可由node-semver解析,它与 npm 作为依赖项捆绑在一起。(npm install semver自己使用。)

以下是 npm 的 semver 实现与 semver.org 上的不同之处:

  • 版本可以以“v”开头
  • 用连字符与主要的三数字版本分隔的数字项目将被解释为“内部版本”编号,并将增加版本。但是,如果标签不是由连字符分隔的数字,则将其视为预发布标签,并且小于没有标签的版本。所以,0.1.2-7 > 0.1.2-7-beta > 0.1.2-6 > 0.1.2 > 0.1.2beta
于 2013-06-02T22:46:07.283 回答
21

简单的答案 - 使用0.1.0

0.1不管用

快乐编码!

于 2019-06-20T04:03:01.503 回答
5

所以是的,简短的回答是“你需要使用语义版本控制”

但其背后的原因是为所有 npm 用户提供一个合理的、统一的包版本。当获得一个包的版本号时,你对作者理解 semver 并正确使用它有一定程度的信心。

于 2013-06-03T06:06:49.283 回答