How to specify npm version when deploying nodejs apps to bluemix? - node.js

I created a node.js application with runtime dependencies of scoped packages in my package.json:
"dependencies": {
"#shawnzhu/mybot" : "latest",
...
},
"engines": {
"npm": ">2.0.0",
"node": "0.10.38"
},
I also have a custom .npmrc that points scope #shawnzhu to my private npm registry.
Currently it works when deploying to heroku, where it upgrades npm to v2.7.x. However, a cf push to bluemix fails with the console output showing:
registry "#shawnzhu/mybot" not found.
After reviewing the whole console output I realized it uses npm v1.4.28 which doesn't support scoped packages.
How can I get npm v2.0.0+ in a node.js app in bluemix?

Before June 15, 2015: This was not possible using the default Node.js buildpack on Bluemix, yet. For now, you can use the community open-source Node.js buildpack:
cf push mynodeapp -b https://github.com/cloudfoundry/nodejs-buildpack
You've specified the npm version in your package.json correctly, so it should work for the community buildpack.
After June 15, 2015: The newest version of the IBM Node.js Buildpack is now available on Bluemix! You can see the full changes at https://developer.ibm.com/bluemix/2015/06/15/bluemix-node-js-buildpack-update/
This buildpack comes with the ability to specify NPM versions by including an "npm" entry in your package.json, like so:
"engines": {
"npm": "xxxxxxx"
},

I was also able to get this working using Node 0.12.2, with the following changes:
In package.json:
"engines": {
"npm": ">2.0.0",
"node": ">=0.12.0"
},

As of the latest Bluemix node.js default buildpack (c.Jun 4, 2015), you can specify a version of npm >2.0.0, which installs a version of npm >2.7, which is the requirement to support and import scoped npm packages. I have tested this for a publicly scoped package and it is up and running in production in Bluemix, using the default node.js buildpack.
If you don't want to revert and use the cf community buildpack, you can use the "engines.npm" property and that should get you up and running, even in node 0.10.x.
In package.json, specify:
"engines": {
"npm": ">2.0.0",
"node": "0.10.x"
}
I've edited this answer for clarity. Many thanks to #shawnzhu for comments. Hope this helps.

Related

How to deploy npm package dependencies to gitlab registry?

I am working in a environment where build env doesn't have access to internet and my application uses npm packages during the build. Till now we have copied the node_modules to source and used them to build. We recently moved to gitlab premium and want to use gitlab registry to store our npm packages. So our issue is gitlab allows to publish only the registry and not its dependencies. But that will not help use because when we do npm install it will to get the some package dependencies from internet(registry.npm.org.js) which will fail as it will not have internet access.
My requirement is i should be able to publish all the dependencies also along with package as tar files in the npm registry itself so that during the build when npm install happens it should download packages from gitlab registry itself.
My package.json looks like this:
{
"name": "#npm-project/aws-sdk-v3-iam-examples",
"version": "1.2.0",
"main": "index.js",
"repository": "git#github.com/awsdocs/aws-doc-sdk-examples/tree/master/javascriptv3/example_code/iam.git",
"author": "Brian Murray <brmur#amazon.com>, Alex Forsyth <alex-git#amazon.com>",
"license": "Apache 2.0",
"dependencies": {
"#aws-sdk/client-sqs": "^3.32.0",
"#aws-sdk/node-http-handler": "^3.32.0",
"#aws-sdk/types": "^3.32.0",
"ts-node": "^9.0.0"
},
"devDependencies": {
"#types/node": "^14.0.23",
"typescript": "^4.0.2"
},
"publishConfig": {
"#npm-project:registry": "https://gitlab.com/api/v4/projects/xxxxx/packages/npm/"
}
}
i want #aws-sdk/client-sqs,#aws-sdk/node-http-handler,#aws-sdk/types packages to be available in my npm registry itself.
it might look something like this,
What you are searching for are mirror/proxy Registries like Nexus, jFrog or Verdaccio. Maintaining all your packages manually will be incredibly tedious.
In the GitLab Docs I can't find such a feature, they only support publishing scoped private packages so packages like ts-node could not be published at all. So it might be an option to setup such a mirror/proxy Registry yourself which could update automatically. Especially Verdaccio is OpenSource, free and easy to setup. Also jFrog+GitLab is a common combination I think but I think it's a paid product.

Error: Cannot find module './shared'

I am attempting to get a Node app with MongoLab working on Heroku. I get the following message in my Heroku logs: "Error: Cannot find module './shared'". I have uninstalled and reinstalled node_modules several times and have also installed a "shared" module, to no avail. The app runs fine on localhost. Is there anything I'm missing?
Just got the same issue. Seems you use latest node v6.0.0.
Please check you use the latest npm on Heroku.
Check the following in your package.json:
...
"engines": {
"node": "6.0.0",
"npm": "3.8.7"
},
...

how to install old version of express.js

How do I install the right version of express and do I have to uninstall 3.x before I install 2.x?
This is the tutorial I am trying to test: http://psitsmike.com/2011/09/node-js-and-socket-io-chat-tutorial/
I used this package.json:
{
"name": "mukhin_chat",
"description": "example chat application with socket.io",
"version": "0.0.1",
"dependencies": {
"express": "2.4.6",
"socket.io": "0.8.4"
}
}
and used the following command:
npm install -d
When I run the app I still get the question: ... are you migrating from Express 2.x to 3.x ...
This is pretty easy, to remove the current version of express, just type
npm uninstall express
Followed by the following command to install a specific version of a package:
npm install express#2.x.x
bro you just need to run this command and your version will be updated at any time.
npm i express#sepecifc version number
for example i was required to use the old version of express so i do like this
npm i --save express#3.20.1

npm doesn't work with node v0.8.5?

I'm deploying a Node app to Heroku and get the following error. If npm doesn't work with recent versions of Node, what are we supposed to use for a package manager? I really liked node_modules and package.json. It seemed very logical.
-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.8.5
Using npm version: 1.0.106
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
Error: npm doesn't work with node v0.8.5
Required: node#0.4 || 0.5 || 0.6
If you're specifying Node.js 0.8.x via "engines" in your package.json, you may also need to set a version for "npm":
{
...
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
}
}
From the Heroku Dev Center for Node.js:
If you do not specify a version, you will get the following defaults:
Node.js: 0.4.7
npm: 1.0.106
That page also includes links to supported version manifests for both.
You've simply got an obsolete version of npm: the current version is 1.1.45 and works just fine with 0.8.x versions of node.

Heroku does not respect npm-shrinkwrap.json

I have a Node.js app with npm-shrinkwrap.json checked in. When I run npm install locally, it installs the versions specified in npm-shrinkwrap.json, but when I push it to Heroku (on the Cedar stack), it seems to ignore the shrinkwrap and simply installs the newest version.
Am I doing something wrong? I don't need to to check in node_modules, do I?
As you say in your answer, when Heroku wrote the Nodejs buildpack, the feature npm shrinkwrap didn't exist.
However, as of version 1.1.2, npm install tries npm-shrinkwrap.json first, falling back to package.json. This means that Heroku respects it (even though the feature hadn't been conceived when Heroku wrote their code). Isaacs is awesome.
So just add to your package.json:
"engines": {
"node": "0.8.x",
"npm": ">=1.1.2"
}
Then run npm shrinkwrap, and git add npm-shrinkwrap.json. Then commit as normal.
As it turns out, Heroku uses npm 1.0.106 at the moment, but shrinkwrap was only added in npm 1.1.2, according to the changelog.
Adding node_modules has solved my problem, until Heroku upgrade their npm.

Resources