简体   繁体   中英

How to specify npm version when deploying nodejs apps to bluemix?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM