Publish development version of NPM package - node.js

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 like 0.0.1-alpha.1.

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.

Related

NPM fails to install types

I have a problem with npm install, in that it won't install #types.
This works fine
npm install --save lodash
However asking for types does not
npm install --save #types/lodash
PS C:\Development\Temp> npm install --save #types/lodash
npm WARN `git config --get remote.origin.url` returned wrong result (git://github.com/types/lodash)
npm WARN `git config --get remote.origin.url` returned wrong result (git#github.com:types/lodash)
npm ERR! git clone git#github.com:types/lodash Cloning into bare repository 'C:\Users\myuser\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-lodash-9eb5372a'...
npm ERR! git clone git#github.com:types/lodash Host key verification failed.
npm ERR! git clone git#github.com:types/lodash fatal: Could not read from remote repository.
npm ERR! git clone git#github.com:types/lodash
npm ERR! git clone git#github.com:types/lodash Please make sure you have the correct access rights
npm ERR! git clone git#github.com:types/lodash and the repository exists.
npm ERR! addLocal Could not install types/lodash
npm ERR! Error: ENOENT: no such file or directory, stat 'C:\Development\Temp\types\lodash'
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/npm/npm/issues>
npm ERR! System Windows_NT 10.0.15063
npm ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\ProgramData\\chocolatey\\lib\\npm\\tools\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "#types/lodash"
npm ERR! cwd C:\Development\Temp
npm ERR! node -v v8.6.0
npm ERR! npm -v 1.4.9
npm ERR! path C:\Development\Temp\types\lodash
npm ERR! syscall stat
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Development\Temp\npm-debug.log
npm ERR! not ok code 0
PS C:\Development\Temp>
This has got me scratching my head. I've updated Chocolatey, NodeJS, NPM to make sure their own the latest versions. Tried the commands on empty folders or an existing TypeScript project - thinking it might be getting confused being ran within a Git repository (error: remote.origin.url). Looking at the GitHub URL it makes no sense git://github.com/types/lodash
I took these examples from MSDN Blog - The Future of Declaration Files
Update: I've uninstalled Node.js and tried reinstalling v6.11.3 LTS or v8.6.0. However the #types command still fails.
Update 2: I've realised Chocolately was masking the npm version. I removed the Chocolately folder, and upgraded npm as per #Louis answer.
Upgrade your npm version to version 4 or 5. I'm mentioning 4 because I ran into problems with 5, and using 4 is still viable. I don't know of any good reason to run an older version.
You are using npm version 1.4.9, as shown in this line of the log:
npm ERR! npm -v 1.4.9
The problem is that npm versions prior to version 2 do not support scoped packages. Packages that begin with an # are scoped packages, so #types/lodash is a scoped package. You need npm version 2 or greater to install it. If you were to use the latest npm in the 1.x series (1.4.29), you'd get a better error message:
npm ERR! Error: This version of npm doesn't support scoped packages (caused by reference to #types/lodash). Update to npm#2+.
Version 1.4.9 did not even know that scoped packages were a thing, so it cannot give a nice error message. It looks like it took the # symbol as signifying that the package name is an address and filled in the missing information with Github as the default host.
The upgrade command I typically use to upgrade npm is:
npm install -g npm
You can specify a specific version by replacing the npm argument with one that gives specific version number. npm#4, for instance, would install the latest npm in the 4.x series. If you don't specify a version number, you get the latest released version.

Install new version of npm and use it instead of the shared one

We are many persons who work on the same server where our projects live. Every one of course has his own virtual environment.
We all share the same node.js v4.4.5 and npm 2.15.5.
However, I need npm >= 3.0.0, so I installed a newer version /usr/local/n/versions/node/8.1.3/bin/npm and I added aliases for node and npm into my ~/.bashrc
# ~/.bashrc
alias node='/usr/local/n/versions/node/8.1.3/bin/node'
alias npm='/usr/local/n/versions/node/8.1.3/bin/npm'
Then I sourced it source ~/.bashrc and I thought it worked because
$ npm --version
5.0.3
Until I run npm run dev
$ npm run dev
> training#1.0.0 dev /home/users/itsme/projects/training
> /usr/local/n/versions/node/8.1.3/bin/node build/dev-server.js
To use this template, you must update following to modules:
npm: 2.15.5 should be >= 3.0.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! training#1.0.0 dev: `/usr/local/n/versions/node/8.1.3/bin/node build/dev-server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the training#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/users/itsme/.npm/_logs/2017-07-06T15_13_11_912Z-debug.log
I don't understand why it seems to be running the shared outdated npm instead of mine.
And here another quite weird thing
$ which npm # shows the shared one
$ `which npm` --version
2.15.5
https://github.com/creationix/nvm
Node version manager makes managing multiple node environments a simple task.
This has solved my problem (based on Oliver Charlesworth's answer)
export PATH="/usr/local/n/versions/node/8.1.3/bin:$PATH"

Azure deployment of Swagger Node.js generated server bundle using Git failing

I'm having some difficulties deploying my project to azure. I've created a web-app and followed all the steps in deployment but it seems that some of the libraries are causing problems in that their system path is too long..
Your expert input is welcome!
Thanks so much.
Below is the log produced by Azure.
Invalid path for filesystem 'D:/home/site/repository/node_modules/swagger-tools/node_modules/swagger-converter/node_modules/lodash.clonedeep/node_modules/lodash._basecreatecallback/node_modules/lodash.bind/node_modules/lodash._createwrapper/node_modules/lodash._basebind/node_modules/lodash._basecreate/.gitattributes': The data area passed to a system call is too small.\r\n
UPDATE:
I removed the node_modules folder and let Azure download the libraries needed. This got further but still produced errors. Below is the past-bin with my errors.
http://pastebin.com/m3BTRYQ4
UPDATE:
I used the console to manual attempt to install the libraries. Here's the results..
D:\home\site>npm install swagger-tools -g
npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\Program Files (x86)\nodejs\4.4.7\node.exe" "D:\Program Files (x86)\npm\2.15.8\node_modules\npm\bin\npm-cli.js" "install" "swagger-tools" "-g"
npm ERR! node v4.4.7
npm ERR! npm v2.15.8
npm ERR! path D:\local\AppData\npm\node_modules\swagger-tools\node_modules\swagger-converter\node_modules\lodash.clonedeep\node_modules\lodash._basecreatecallback\node_modules\lodash.bind\node_modules\lodash._createwrapper\node_modules\lodash._basecreatewrapper\package.json.1152100249
npm ERR! code EINVAL
npm ERR! errno -4071
npm ERR! syscall rename
npm ERR! EINVAL: invalid argument, rename 'D:\local\AppData\npm\node_modules\swagger-tools\node_modules\swagger-converter\node_modules\lodash.clonedeep\node_modules\lodash._basecreatecallback\node_modules\lodash.bind\node_modules\lodash._createwrapper\node_modules\lodash._basecreatewrapper\package.json.1152100249' -> 'D:\local\AppData\npm\node_modules\swagger-tools\node_modules\swagger-converter\node_modules\lodash.clonedeep\node_modules\lodash._basecreatecallback\node_modules\lodash.bind\node_modules\lodash._createwrapper\node_modules\lodash._basecreatewrapper\package.json'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues
npm ERR! Please include the following file with any support request:
npm ERR! D:\home\site\npm-debug.log
D:\home\site>
Looks like swagger-tools tries to use a command that only works with Linux / OSX systems.
Any help is appreciated!
I try to use a higher node.js version which will include a npm with version grander than 3. And it worked successfully on my side.
Please try to specify a node.js version in your package.json file, E.G.:
"engines": {
"node": ">=5.0.0"
}
And then deploy to Azure via Git again.
Any further concern, please feel free to let me know.

Travis - Control Which Node Version is used for NPM Installs

I am attempting to install an npm package (markdown-pdf) as part of my Travis-CI build which I believe is not compatible with old versions of Node. On my local machine, I am running Node version 0.10.36, and it works here, so I added what I believe to be the accepted way of defining a specific version to the top of my .travis.yml file (although I'm not clear on that either). The MCVE version of the full file is below.
language: node_js
node_js:
- "0.10"
install:
- sudo apt-get install npm
- npm config set registry http://registry.npmjs.org/
- sudo npm install -g markdown-pdf
script:
- echo "stuff was installed."
At the top of the build log, I see the following, which seems to indicate that my change worked:
$ nvm install 0.10
######################################################################## 100.0%
Now using node v0.10.40
$ node --version
v0.10.40
$ npm --version
1.4.28
$ nvm --version
0.23.3
However, further down the log, when travis attempts to execute sudo npm install -g markdown-pdf, the log reports the following. Notice that it suggests that the package might not be compatible with the version of Node that is installed, and it claims that I'm using Node v0.6.12.
$ sudo npm install -g markdown-pdf
npm http GET http://registry.npmjs.org/markdown-pdf
npm http 200 http://registry.npmjs.org/markdown-pdf
npm ERR! Error: No compatible version found: markdown-pdf
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR! at installTargetsError (/usr/share/npm/lib/cache.js:488:10)
npm ERR! at next_ (/usr/share/npm/lib/cache.js:438:17)
npm ERR! at next (/usr/share/npm/lib/cache.js:415:44)
npm ERR! at /usr/share/npm/lib/cache.js:408:5
npm ERR! at saved (/usr/share/npm/lib/utils/npm-registry-client/get.js:147:7)
npm ERR! at Object.oncomplete (/usr/lib/nodejs/graceful-fs.js:230:7)
npm ERR! You may report this log at:
npm ERR! <http://bugs.debian.org/npm>
npm ERR! or use
npm ERR! reportbug --attach /home/travis/build/ahemmeter/ahemmeter.github.io/npm-debug.log npm
npm ERR!
npm ERR! System Linux 2.6.32-042stab108.3
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "markdown-pdf"
npm ERR! cwd /home/travis/build/ahemmeter/ahemmeter.github.io
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message No compatible version found: markdown-pdf
npm ERR! message No valid targets found.
npm ERR! message Perhaps not compatible with your version of node?
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/travis/build/ahemmeter/ahemmeter.github.io/npm-debug.log
npm not ok
I think I've provided enough information, but you can also look at the public build logs for the project and the github repository it's building.
Have I made a mistake in declaring which version of Node to use? Do I need to (or should I) do something similar for npm, nvm, and markdown-pdf? How can I force npm-install to use the newer version of Node rather than the old one?
Note that I set the repository to download over HTTP instead of HTTPS. When I did that, the error message changed from "failed to fetch from registry: markdown-pdf" to "No compatible version found: markdown-pdf", which seemed like a step in the right direction, so I kept it; however, I mention it here in case there is a possibility that it causes a conflict.
In order to specify dependencies when using node.js, travis seems to expect a package.json file. You can also use this to specify which version of the node package you want to download.
.travis.yml
language: node_js
node_js:
- "0.10"
script:
- echo "stuff was installed."
package.json
{
"name" : "ahemmeter.github.io",
"version" : "0.0.0",
"dependencies" : {
"markdown-pdf" : "5.3.x"
}
}
Note from OP: This is the answer I found, but If someone posts an answer that does not involve using a package.json file (this is just a test suite rather than a package and I don't want to publish it as a package), I'll mark that answer as accepted.

Issue installing hiredis on AWS Linux using OpsWorks

I'm using OpsWorks to deploy my custom node.js application. I'm not a Chef expert and thought this would be an easy process however I keep hitting snags. This most recent issue is really setting me back.
Basically I'm using a package called "Kue" which depends on a Node package called Hiredis. Hiredis is implemented at the C-level (as far as I understand) and uses some Python level compilation tools.
It seems that the default Chef script that OpsWorks uses keeps failing at the point where Kue then Hiredis is being installed. The following is the log when the instance attempts deploying the application: http://codepad.org/RXxKXqBq
Upon Googling some people are indicating its an issue with the Python version that AWS Linux is using. Note that I'm using the default Node.js application Chef recipes which can be found here: https://github.com/aws/opsworks-cookbooks/tree/release-chef-11.10/opsworks_nodejs
I'm not that familiar with node packages and version compabylity but from log that you have shared it seems it's problem in one of the node packages that you're using called amdefine:
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /home/deploy/.npm/amdefine/0.1.0/package/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! System Linux 3.14.26-24.46.amzn1.x86_64
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--production"
npm ERR! cwd /srv/www/my_api/releases/20141214002817
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! file /home/deploy/.npm/amdefine/0.1.0/package/package.json
It can be fixed by npm cache clean or by changing version of nodejs, as you found too probably.
For adding command npm cache clean you must create new recipe or add it to your wrapper cookbook. Only thing that should be satisfied is that this command should be after installing node and before installing packages.
If yo want to change version, you can chceck default nodejs recepie you can see that requred version of installed nodejs is definded in attributes file for that cookbook.
So you can override default value with default[:opsworks_nodejs][:version] attribute.

Resources