【问题标题】:How to resolve Heroku error: Cannot find module 'puppeteer-cluster'?如何解决 Heroku 错误:找不到模块“puppeteer-cluster”?
【发布时间】:2020-04-29 07:32:52
【问题描述】:

我正在尝试从我的 Heroku 应用程序运行单个脚本。我正在尝试使用以下命令在 Heroku 服务器上运行它:

heroku run node path/to/myScript.js

当我在本地运行该脚本时,它可以完美运行。但是尝试在 Heroku 上远程运行它时出现错误。

我希望看到脚本运行正确的证据,但我收到了以下错误。

错误:找不到模块“puppeteer-cluster”

该依赖项位于我的 package.json 中

包.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"
      }
    },
    ...

到目前为止我已经尝试过什么。

  1. 我尝试使用以下内容确保将所有新文件正确提交到 git。

    git add .
    git commit -m "update"
    git push heroku master
    
  2. 我尝试了以下命令序列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. 我尝试从头开始重建和重新部署我的应用程序,如下所示。

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

但我得到了错误:

my-awesome-app 这个名字已经被占用了

  1. This page lists the following,我试过没有成功。

heroku config:set NODE_MODULES_CACHE=false
接下来,您应该确保不会意外地将模块签入 git。
最后,您应该检查以确保您的依赖项在 package.json 中正确列出。

  1. 我还尝试了仔细检查以确保我没有跟踪任何 git 文件检查以下as suggested here

    git ls-files | grep node_modules
    
  2. 在检查了本地的节点版本后,我在 package.json 中添加了一个节点版本。

    node --version
    v12.10.0
    
包.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.

我做错了什么?接下来我应该尝试什么?

【问题讨论】:

    标签: javascript node.js git heroku


    【解决方案1】:

    以下内容适用于我的情况。

    我在本地重新安装了所有依赖项。

      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
    

    然后重新部署到 Heroku。

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

    Credit to this SO answer.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-25
      • 2021-04-08
      • 2021-08-31
      • 2022-07-22
      • 2022-10-12
      • 2019-09-25
      • 2012-02-19
      相关资源
      最近更新 更多