質問

When deploying an OpenShift node.js project with a depdency on browserify 4.0.0, I get an error installing browserify's dependencies. Specifically:

...
remote: npm ERR! Error: No compatible version found: stream-browserify@'^1.0.0'
remote: npm ERR! Valid install targets:
remote: npm ERR! ["0.0.0","0.0.1","0.0.2","0.0.3","0.0.4","0.1.0","0.1.1","0.1.2","0.1.3","1.0.0"]
...

Given that stream-browserify's version is ^1.0.0 according to browserify's depdency and that openshift is suggesting 1.0.0 is a valid install target, why is this failing? I have seen this error in other cases, whenever the highest available openshift version fits the careted package.json version.

Am I misunderstanding what the caret means? Is this an OpenShift bug?

My package.json:

{
  "name": "SampleApp",
  "version": "1.0.0",
  "description": "do things online",
  "keywords": [
    "OpenShift",
    "Node.js",
    "application",
    "openshift"
  ],
  "author": {
    "name": "J",
    "email": "j@email.com",
    "url": ""
  },
  "homepage": "http://www.openshift.com/",
  "repository": {
    "type": "git",
    "url": "https://github.com/openshift/origin-server"
  },
  "engines": {
    "node": "0.x",
    "npm": "1.x"
  },
  "dependencies": {
    "body-parser": "1.x",
    "browserify": "4.0.0",
    "cookie-parser": "1.x",
    "cookie-session": "1.x",
    "express": "4.x",
    "fast-csv": "0.x",
    "multer": "0.0.5",
    "pg": "3.x",
    "sql": "0.x",
    "xlsx-extract": "0.0.4"
  },
  "devDependencies": {
  },
  "bundleDependencies": [],
  "private": true,
  "main": "server.js",
  "scripts": {
    "build-js": "browserify public/index.js -o public/index-bundle.js & browserify public/intake.js -o public/intake-bundle.js",
    "start": "npm run build-js && node server.js"
  }
}
役に立ちましたか?

解決

This behaviour could be because of different versions on node and npm on your local machine and openshift environment. Start by fixing "engines" attribute in your package.json, something as below:

"engines": {
    "node": ">= 0.10",
    "npm": ">= 1.4"
  }

If still the issue is there (on openshift) it is due to the unavailability of the nodejs/npm required versions on openshift environment. For example, as of today, on my local machine I may be using node version 0.10.28 and npm version 1.4.9, but on openshift nodejs default cartridge I have to be content with nodejs version 0.10.5 and npm version 1.2.17, which is a big gap.

So, in this case, the easiest way to get around is by using "npm shrinkwrap", which freezes the nested dependency versions that ought to be used, hence doing away with varied behaviour of npm versions to figure out the nested dependency to install.

Can read about shrinkwrap here: https://www.npmjs.org/doc/cli/npm-shrinkwrap.html

So, on your local machine:

  1. run npm install and make sure everything works.
  2. fire npm shrinkwrap This will create a file - "npm-shrinkwrap.json", with the required shrinkwrap info. Add, commit and push the file to the openshift git repo.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top