Search code examples
node.jsherokubrowserify

Heroku - error running browserify on Node deployment


I'm trying to deploy a Node app to Heroku, but I'm having an issue successfully running browserify when the app is deployed.

When I'm running locally, I browserify my script with npm run bundle like so (from package.json):

"bundle": "./node_modules/browserify/bin/cmd.js build/main.js -o public/scripts/bundle.js

which browserifies the script in build/main.js and puts it into public/scripts/bundle.js.

For deploying to Heroku, I added

"postinstall": "npm run bundle"

However, when I deploy, I get the following error:

Error: ENOENT: no such file or directory, open 'public/scripts/bundle.js.tmp-browserify-59309133185877094263'

Well, that's correct, that file shouldn't exist... yet. When I run npm run bundle locally, I do see that file briefly pop into existence, but then it is quickly removed and I'm left with a nice updated bundle.js.

I read through Heroku's docs on this, but I'm miffed... can anyone clarify how to get through this?

For reference, here are the relevant parts of my package.json:

"scripts": {
    "bundle": "./node_modules/browserify/bin/cmd.js build/main.js -o public/scripts/bundle.js",
    "postinstall": "npm run bundle"
},
"dependencies": {
    "body-parser": "^1.17.1",
    "browserify": "^14.1.0",
    "ejs": "^2.5.6",
    "express": "^4.15.2",
    "jquery": "^3.2.1",
    "path": "^0.12.7",
    "superagent": "^3.5.2"
},
"devDependencies": {},
"engines": {
    "node": "6.8.1",
    "npm": "4.0.5"
}

Solution

  • Solved! I had bundle.js included in my global gitinore configuration. Just had to take that out, good to go!