NPM doesn't install module dependencies when deploying a Grunt app to heroku

Viewed 4738

I'v made a static single page site using grunt. I'm now trying to deploy it to heroku using the heroku-buildpack-nodejs-grunt for node grunt.

Below is a pic of my root directory:

project root directory image

Here's my Gruntfile package.json:

Procfile:

web: node index.html

When I run $ git push heroku master it gets to the Gruntfile and fails:

-----> Found Gruntfile, running grunt heroku:production task
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?

The above errors proceed to list all local NPM modules as not found. If I list all loadNpmTasks instead of using "load-grunt-tasks", I get the exact same error.

When I $ heroku logs I get:

Starting process with command `node web.js`
Error: Cannot find module '/app/web.js'

Can anyone see where I've gone wrong?

4 Answers

I faced a similar problem with Heroku not installing all of my dependencies, while I had no issue locally. I fixed it by running

heroku config:set USE_NPM_INSTALL=true

into the path, where I deployed my project from. This instructs Heroku to install your dependencies using npm install instead of npm ci, which is the default! From Heroku dev center:

"Heroku uses the lockfiles, either the package-lock.json or yarn.lock, to install the expected dependency tree, so be sure to check those files into git to ensure the same dependency versions across environments. If you are using npm, Heroku will use npm ci to set up the build environment."

Related