0

I'm trying to run a single script from my Heroku app. I'm trying to run it on the Heroku server with the following command:

heroku run node path/to/myScript.js

This script works perfectly when I run it locally. But I get an error when trying to run it remotely on Heroku.

I expect to see evidence the script ran correctly but instead I get the following error.

Error: Cannot find module 'puppeteer-cluster'

That dependency is located in my package.json

package.json
  "dependencies": {
    ...
    "puppeteer-cluster": {
      "version": "0.18.0",
      "resolved": "https://registry.npmjs.org/puppeteer-cluster/-/puppeteer-cluster-0.18.0.tgz",
      "integrity": "sha512-xxxxxxxx+xxxxxxxxxxxxxxxxxxxxx==",
      "requires": {
        "debug": "^4.1.1"
      }
    },
    ...

What I have tried so far.

  1. I tried to make sure I was committing all the new files to git correctly with the following.

    git add .
    git commit -m "update"
    git push heroku master
    
  2. I tried the following sequence of commands based on this SO answer.

    $ heroku config:set NODE_MODULES_CACHE=false
    $ git commit -am 'disable_node_modules_cache' --allow-empty
    $ git push heroku master
    
  3. I tried to rebuild and re-deploy my app from scratch as follows.

    heroku create my-awesome-app --buildpack heroku/nodejs
    

But I got the error:

The name my-awesome-app is already taken

  1. This page lists the following, which I tried without success.

heroku config:set NODE_MODULES_CACHE=false
Next, you should ensure that you aren't accidentally checking your modules into git.
Finally, you should check to ensure that your dependencies are correctly listed in package.json.

  1. I also tried double checking to make sure I'm not tracking any git files checking the following as suggested here.

    git ls-files | grep node_modules
    
  2. I added a node version to my package.json after checking the node version I have locally.

    node --version
    v12.10.0
    
package.json
  "name": "myapp",
  "description": "a really cool app",
  "version": "0.1.0",
  "engines": {
    "node": "12.10.0"
  },
  1. I also reviewed the information at this location.

What am I doing wrong? And what should I try next?

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207

1 Answers1

0

The following worked for my case.

I re-installed all my dependencies locally.

  rm -rf node_modules
  # <manually remove node_modules>
  # <manually remove package-lock.json>
  npm cache clean --force # `npm cache clean` is obsolete
  npm cache verify
  npm install

Then redeployed to Heroku.

  git add .
  git commit -m "update"
  git push heroku master

Credit to this SO answer.

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207