ericclemmons/per-env

works on local machine but nothing on Heroku

hadifarnoud opened this issue · 4 comments

per-env works just fine locally. npm install correctly runs different scripts based on NODE_ENV. but when I deploy on heroku, none of them works.

seems like heroku doesn't recognise install:production etc. here is my package.json

@hadifarnoud Do you have your environment set for production?

https://devcenter.heroku.com/articles/nodejs-support#configuring-npm

I remember when I used Heroku this part always got me...

I changed my package.json to this and it worked. I had to add heroku-postbuild.

{
  "name": "shop-admin",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "engines": {
    "node": "4.4.7",
    "npm": "3.9.6"
  },
  "author": "Hadi Farnoud",
  "license": "ALL RIGHTS RESERVED",
  "devDependencies": {
    "requirejs": "^2.2.0"
  },
  "dependencies": {
    "express": "^4.13.4",
    "per-env": "^1.0.2"
  },
  "per-env": {
    "production": {}
  },
  "scripts": {
    "build": "per-env",
    "build:development": "r.js -o app/build/build.style.js && r.js -o app/build/app.build.js && sh app/build/deploy.sh",
    "build:staging": "r.js -o app/build/build.style.js && r.js -o app/build/app.build.js && node cdn.js",
    "build:production": "r.js -o app/build/build.style.js && r.js -o app/build/app.build.js && node cdn.js",
    "start": "per-env",
    "start:development": "npm run build:development",
    "prestart:production": "npm run build",
    "start:production": "node server.js",
    "prestart:staging": "npm run build",
    "start:staging": "node server.js",
    "heroku-postbuild": "npm run build"
  }
}

and I also had to disable NPM_CONFIG_PRODUCTION

Ahhh, interesting! That's new to me too :)

https://devcenter.heroku.com/articles/nodejs-support#heroku-specific-build-steps

Thanks for updating!