entriol's avatar

Deploying Laravel Mix to Heroku

I successfully deployed Laravel to Heroku. Added buildpacks in this order.

=== app Buildpack URLs
1. heroku/nodejs
2. heroku/php

And also in package.json, I provided scripts to build asssets in production.

"postinstall": "npm run production"

Everything works except one thing. Versioning. In webpack I have version(), and it works fine when I fire npm run production on my local machine. But in heroku, versioning does not working. I pasted output from heroku.

remote:        > @ production /tmp/build_8c7781f6ff90b919667b337b3006842e
remote:        > node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
remote:
remote:       95% emitting
 DONE  Compiled successfully in 30218ms
remote:
re            Asset      Size  Chunks                    Chunk Names
remote:        /js/app.js    294 kB       0  [emitted]  [big]  /js/app
remote:        /css/app.css    135 kB       0  [emitted]         /js/app
remote:        mix-manifest.json  66 bytes          [emitted]
remote:        Done in 66.33s.

Scripts minimized and merged, but there's no versioning. Any idea to fix it?

In case you ask it, this is environment on heroku for nodejs: I use node ^7.x, npm ^4.x

remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=false
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=false
0 likes
6 replies
guillermo_rojas's avatar

Not answering your question, but how did you npm install? I have both buildpacks, but it says bash: npm: command not found

daanlo's avatar

@guillermo_rojas - make sure to add the buildpacks in the correct order. That resolved the issue of npm install not working for me.

cjfloss's avatar

For future reference,

Heroku will look for a script named "build" in your package.json. Without this your mix-manfest.json, app.css and app.js will not be created and you'll end up wasting 1 hour thinking "why Heroku doesn't build my files" 😅

2 likes
colinlongworth's avatar

Can I ask you for an example of this script? I'm using Laravel Spark and my builds are failing, I think because I don't have a 'build' script.

klys's avatar

Is funny because what everyone is looking for over here is a procfile example which is available on the heroku website

https:// devcenter.heroku.com /articles /procfile

Please or to participate in this conversation.