David
David

Reputation: 14404

Heroku cannot serve files from bower_components

I'm having trouble getting Heroku to find resources in the bower_components folder, but the site works fine on localhost.

I created an express-node.js site. The structure of the site looks like this.

site
-> bower_components
--> jquery
---> dist
----> jquery.min.js
-> Other folders
-> app.js

I've made the bower_components folder public like this.

app.use(express.static(path.join(__dirname, 'bower_components')));

To retrieve the jquery file, I've specified it like so in the html

<script src="/jquery/dist/jquery.min.js"></script>

Why does this work on localhost but not when I deploy it to Heroku?

Upvotes: 0

Views: 634

Answers (2)

Raja Sekar
Raja Sekar

Reputation: 2130

Make sure you have bower in the package.json file and include post-install script

 "scripts": {
    "postinstall": "bower install"
  },

If you dont have bower in package.json file, again it will result in an error.

Upvotes: 1

David
David

Reputation: 14404

I fixed it by putting postinstall into package.json

  "scripts": {
    "postinstall": "bower install"
  },

Upvotes: 3

Related Questions