Publish development version of NPM package

2019-03-29 09:14发布

How can I publish development version of NPM package?

I tried to set "dev" value for version field in package.json but I got an error when publishing it:

$ npm publish
npm ERR! Error: Invalid version: "dev"
npm ERR!     at Object.module.exports.fixVersionField (/usr/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:180:13)
npm ERR!     at /usr/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:29:38
npm ERR!     at Array.forEach (native)
npm ERR!     at normalize (/usr/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:28:15)
npm ERR!     at final (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:310:33)
npm ERR!     at then (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:33)
npm ERR!     at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:299:40
npm ERR!     at fs.js:266:14
npm ERR!     at /usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:103:5
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/isaacs/npm/issues>

npm ERR! System Linux 3.11.0-15-generic
npm ERR! command "node" "/usr/bin/npm" "publish"
npm ERR! cwd /home/ionicabizau/package-name
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.23
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/ionicabizau/package-name/npm-debug.log
npm ERR! not ok code 0

Which are the closest alternatives?

标签: node.js npm
2条回答
姐就是有狂的资本
2楼-- · 2019-03-29 10:07

You can upload prerelease tags to npm. These tags will not be matched by normal semver range semantics, but will allow you to both use and upload development versions. An example would be 1.3.5-alpha.3. If you're uploading something that has no version yet, then a reasonable use would be something like 0.0.1-alpha.1.

查看更多
神经病院院长
3楼-- · 2019-03-29 10:18

NPM package version must meet requirements of semver

A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes. X is the major version, Y is the minor version, and Z is the patch version. Each element MUST increase numerically. For instance: 1.9.0 -> 1.10.0 -> 1.11.0.

So using dev as a version number is not allowed.

Also it is not recommended to publish any code which is in development state. If you want to test your module within different module you can include that module using relative path or using git remote URL.

Example:

Let's say that the module which you are developing is called foo and you would like to test it in module bar, script file bar/index.js. Let's assume both module directories are in the same parent directory. Instead of publishing unfinished module foo to npm and install it in module bar, you can do as follows:

var foo = require('../foo')

As suggested by Ionicã Bizãu (comments below), you can also use npm install with git remote URL e.g.

npm install <git remote url>

NPM install documentation provides more details (option g) on that installation method.

Alternatively you can use approach proposed in this post: Locally test your npm modules without publishing them to npmjs.org.

EDIT

There is another alternative solution which require npm link command:

  • Execute npm link command inside your developed module. That will create globally-installed symbolic link from prefix/package-name to the current folder
  • Another step is to execute npm link package-name (where package-name is a name of your developed package) in some other location (other module / application which you use to test the developed module). That will create a symlink from the local node_modules folder to the global symlink (which was created in the first step).

Note that you may need to run the first command as a privileged user (usually sudo helps) in some operating systems.

With symlinks in place you will be able to add changes to your developed module and see their results instantly in other linked modules.

I hope that will help.

查看更多
登录 后发表回答