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?
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 like0.0.1-alpha.1
.NPM package version must meet requirements of semver
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 modulebar
, script filebar/index.js
. Let's assume both module directories are in the same parent directory. Instead of publishing unfinished modulefoo
to npm and install it in modulebar
, you can do as follows:As suggested by Ionicã Bizãu (comments below), you can also use npm install with git remote URL e.g.
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:npm link
command inside your developed module. That will create globally-installed symbolic link fromprefix/package-name
to the current foldernpm link package-name
(wherepackage-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.