How to update npm on an OpenShift gear? - node.js

How can I update npm on OpenShift?
I'm having problems while deploying because npm started using ^1.2.3 version notations and it's not compatible with the current npm in my application:
remote: npm ERR! Error: No compatible version found: through#'^2.3.4'
remote: npm ERR! Valid install targets:
remote: npm ERR! ["0.0.1","0.0.2","0.0.3","0.0.4","0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","1.0.0","1.1.0","1.1.1","1.1.2","2.0.0","2.1.0","2.2.0","2.2.1","2.2.2","2.2.4","2.2.5","2.2.6","2.2.7","2.3.1","2.3.2","2.3.3","2.3.4"]
Is there a way of fixing this, or I'll have to go back to outdated packages?

OpenShift does not provide root access to developers, but you can still select a custom version of npm by running your own nodejs binary in user space.
Developers can also package up their own custom nodejs cartridge, allowing teams to define and standardize their dependencies in a reusable way.
Here is an answer that helps you run a custom version of Nodejs on OpenShift
You can also try working with user-defined npm globals on OpenShift

Related

ArcGIS JS API 4.7 and NPM error

I am trying to install ArcGIS JS API 4.7 with npm (for a Vue.JS application), and when running
npm install arcgis-js-api
I am getting a NPM error:
npm ERR! code E404
npm ERR! 404 Not Found: #dojo/i18n#~0.6.0
I am using the latest version of Node (v10), but I also tried it with v9 and v6.
Has anyone faced it in the past?
Is it possible you are using a different NPM mirror? Maybe for private packages?
Does the answer provided in this SO answer help you?

Sails.js missing modules

Experiencing npm module troubles using sails.js.
The first problem was - the contents of assets/ was not being replicated to .tmp/public as documentation indicates. There have been other errors as well.
Research has shown - there are missing modules, one of which is grunt. Doing a
npm install grunt
does make the .tmp/public start working.
But there have been other errors when trying to use the framework.
Install Details:
Server instance: Ubuntu 14.04.1 LTS
(recently deployed, no other changes to server except for node and sails.js)
node --version
v0.12.4
(built from sources)
npm -v
2.10.1
sails --version
0.11.0
sails installed using:
sudo npm install sails -g
Create a new application:
sails new testproject
cd testproject
npm list
produces a long list of missing npm modules to stderr:
npm ERR! missing: colors#~0.6.2, required by grunt#0.4.2
npm ERR! missing: grunt#~0.4.0, required by grunt-contrib-clean#0.5.0
npm ERR! missing: lodash#~2.4.1, required by grunt-contrib-coffee#0.10.1
npm ERR! missing: grunt#~0.4.0, required by grunt-contrib-coffee#0.10.1
npm ERR! missing: grunt#~0.4.0, required by grunt-contrib-concat#0.3.0
npm ERR! missing: grunt#~0.4.0, required by grunt-contrib-copy#0.5.0
and several others.
This seems inexplicable - how could this (missing npm modules) be overlooked? I am new to node - and could have missed something.
Reviewing the getting started page, I didn't notice anything obvious.
This framework seems well-designed - uses some great npm modules.
Has anybody experienced these and found what is needed to fix?
To resolve the missing: colors#~0.6.2, required by grunt#0.4.2 , just navigate to the node_modules/grunt, do a npm install to install the missing dependencies.

Installing Node.js modules from file system on Azure Websites

I have a Node.js app running as an Azure Website and doing my deployments using Git. The app requires a module that's private (i.e. written by me, no relevance to anyone else and thus not available in NPM) and common to my other projects. Let's say the module is located in ./lib/mymodule and it has its own dependencies in its package.json file. The problem is I cannot figure out how to have Azure install the dependencies of my own module. I would like to avoid having to add my node_modules directory under version control (currently .gitignor'd) or having to add the module's dependencies as my app's dependencies (which is ugly and a bit inconvenient).
It's trivial to get this working on my local dev environment. The first thing I did was simply include my own module as a local dependency in my package.json as described in https://docs.npmjs.com/files/package.json (see section "Local Paths"). A simple npm install would now install my own module nice and easy. Since I know that Azure runs npm install every time I deploy a new version, I figured this is all I need. Turns out I was wrong: local paths in package.json dependencies section were only introduced in NPM 2.0.0 and Azure is running NPM 1.4.x, so the deployment obviously failed. Ok then, can I run a different version of NPM in Azure? In theory, yes, but practice seems to be something else. I tried out https://github.com/glennblock/azure-node-runtime-selector but to no avail. Here's some of the deployment output:
remote: Handling node.js deployment.
remote: KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
remote: ............
remote: node version: 0.11.14
remote: ..............
remote: 2.1.18
remote: npm version: 1.4.6
remote: An error has occured during web site deployment.
remote: npm failed
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
Apparently it fails to install any NPM version >= 2.0.0.
Ok then, this is not so bad, I figured. I can work with an older version of NPM, I just need to run another npm install to install my own module, as NPM documentation hints. So I took the local dependency away from my package.json and simply run npm install ./lib/mymodule. Nice and easy... on my local. I dug up instructions how to run custom commands on deployment in Azure: just run azure site deploymentscript --node and edit deploy.sh it creates. Just to ensure the custom deployment script works at all, I made one deployment without editing anything. Worked ok. Then I added a line in deploy.sh (around line 111):
# 3. Install npm packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
eval $NPM_CMD install --production
eval $NPM_CMD install ./lib/mymodule #This line added by me
exitWithMessageOnError "npm failed"
cd - > /dev/null
fi
Nope. This is what I get:
remote: Installing npm packages...
remote: npm ERR! addLocal Could not install ./lib/mymodule
remote: An error has occurred during web site deployment.
remote: npm ERR! Error: ENOENT, stat 'd:\home\site\wwwroot\lib\mymodule'
remote: npm failed
...snip...
remote:
remote: npm ERR! System Windows_NT 6.2.9200
remote: npm ERR! command "d:\\Program Files (x86)\\nodejs\\0.10.28\\node.exe" "D:\\Program Files(x86)\\npm\\1.4.9\\node_modules\\npm\\bin\\npm-cli.js" "install" "./lib/mymodule"
remote: npm ERR! cwd d:\home\site\wwwroot
remote: npm ERR! node -v v0.10.28
remote: npm ERR! npm -v 1.4.9
remote: npm ERR! path d:\home\site\wwwroot\lib\mymodule
remote: npm ERR! code ENOENT
remote: npm ERR! errno 34
remote: npm
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
This is where I got stuck. I tried playing around with the path, guessing that Windows is mangling it somehow, but haven't found a working solution yet. The weird thing is that ./lib/mymodule would seem to resolve to d:\home\site\wwwroot\lib\mymodule which look just fine to me and DOES exist, at least after deployment when I FTP'd in to take a look.
I would appreciate any and all help in either getting NPM 2.x.x working or my making custom deployment go through. Or maybe there's an alternative to managing my local modules I haven't thought of? And if all else fails, maybe I'll just commit my node_modules or manage my dependencies manually. I've already used way too much time to resolve what first seemed like a trivial issue. :)
Azure WebSites team will be shipping support for npm 2.1.17 out-of-the box by end of the month (Jan'15). Hope this will help you unblock you.

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.

How to override a npm install version check failure?

Is there a way to override npm's version checking against a packages.json file from command line (npm install command)?
I would like to try and install/run a package even though it doesn't match my node.js version.
This is the error I am getting:
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: canvas#0.6.0
npm ERR! Required: {"node":"0.4.x"}
npm ERR! Actual: {"npm":"1.0.8","node":"v0.5.0-pre"}
Thanks
What you could do is go to github package and update the package.json. Then just install it locally. But most of the times these version numbers are there for a reason. The node.js api changes sometimes(I believe 0.5.0-pre changed, because socket.io also fails with 0.5.0-pre).
If you for example install nvm, nave you can keep several version of node.js side-by-side easily.
If all else fails you could still manually download and copy the files in your node_modules folder

Resources