18

当我尝试将我的 nodejs 应用程序推送到 heroku 时git push heroku master,我得到了这个:

Counting objects: 975, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (862/862), done.
Writing objects: 100% (975/975), 3.74 MiB | 80.00 KiB/s, done.
Total 975 (delta 70), reused 0 (delta 0)

-----> Node.js app detected
-----> Resolving engine versions
   Using Node.js version: 0.10.15
   Using npm version: 1.3.3
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
   npm ERR! install Couldn't read dependencies
!     Push rejected, failed to compile Node.js app

To git@heroku.com:hidden-reaches-9268.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:hidden-reaches-9268.git'

这是我的 package.json:

{
  "name": "fnBoard",
  "version": "0.0.1",
  "private": true,
  "scripts": {
  "start": "node server.js"
},

  "dependencies": {
   "socket.io": "0.9.x"
},
   "engines": {
     "node": "0.10.x",
     "npm": "1.3.x"
   }
}

里面有一堆错误,我不知道为什么会这样。请帮忙。-谢谢

4

10 回答 10

21

我在ReactJS工作,我正在尝试在Heroku服务器上部署我的项目。当时我发现同样的错误是这样的:

推送被拒绝,无法编译 Node.js 应用程序。

在此处输入图像描述

解决方案是:

如果你使用纱线:

git rm yarn.lock

git push heroku 大师

如果你使用 npm:

git rm package-lock.json

git push heroku 大师

于 2018-04-03T04:37:14.763 回答
12

完成这项工作的最简单方法是将 node_modules 添加到您的 .gitignore 中。这里有更多信息:无法将 node.js 应用程序部署到 heroku

于 2013-09-07T10:11:34.693 回答
7

添加 node_modules 可能很容易,但在这里不是正确的方法。相反git push -f heroku master,为了强制推送您的更新,告诉 heroku 覆盖任何预先存在的 node_modules。这样你的 git repo 就不会被节点库所困扰。

于 2014-01-09T19:43:50.660 回答
2

尝试为你的 package.json 设置一个 heroku-postbuild 脚本,并确保包含你的引擎。

"scripts": {
        "heroku-postbuild": "npm run build"
    },
"engines": {
        "npm": "5.6.0",
        "node": "8.10.0"
      }

我会尽量避免不惜一切代价强制推送任何东西,无论是 github 还是 heroku。

于 2019-01-20T03:02:46.670 回答
1

我解决了这个问题。
我得到了同样的错误:

“推送被拒绝,无法编译 Node.js 应用程序”

但我的日志抱怨这个未知选项:

'--target'

我在package.json上解决了这个问题,我在下面找到了这行代码:

"postinstall": "ng build --aot --target=production"

我删除了--target=production.

在我的终端上: 然后
我再次提交 并完成了。$ git commit -m 'anything here'
$ git push heroku master

于 2019-02-17T02:41:41.553 回答
0

我有同样的问题,问题出在 git add 上。我忘记添加 node_modules 文件。我关闭了终端并再次运行 Heroku 和 NodeJs [1] 入门中给出的命令集。应用程序已成功推入堆栈。

于 2019-10-01T05:29:06.987 回答
0

问题 当您使用 Yarn 安装节点模块时,它会生成一个 yarn.lock 文件,其中包含运行命令时它安装的确切模块的列表。如果 package.json 中的依赖项发生了变化,但 Yarn 可执行文件没有生成新的 yarn.lock 文件,我们会导致构建失败,以防止可能在运行时影响应用程序的细微错误和安全问题。

解决方案 当您的应用程序使用 Yarn 但其他一些工具修改 package.json 文件而不调用 yarn install 时,通常会出现此问题。一个例子是使用 npm 来安装新模块而不是 Yarn,或者手动更新版本要求。

要解决此问题,请运行 yarn install 并检入更新的 yarn.lock 文件。

确保您已删除 package.lock 文件并在推送之前提交相同的内容。

于 2020-07-11T13:59:22.770 回答
0

我将其修复为join不属于 Node.js 的导入模块的路径。更多信息在这里 https://stackoverflow.com/a/64772154/12982656

于 2020-11-10T15:53:51.843 回答
0
  1. git rm package-lock.json
  2. npm 初始化 -y
  3. npm 安装
  4. 混帐添加。
  5. git commit -m "更改"
  6. git push heroku main
于 2021-12-19T19:23:02.617 回答
0

我通过删除package lock.json然后再次 删除锁定文件后解决了这个git add .问题。git commit

于 2022-01-23T18:20:56.487 回答