简体   繁体   English

无法将 node.js 应用程序部署到 heroku

[英]Fail to deploy node.js application to heroku

I am trying to deploy a simple node.js express-based application to heroku, something which is apparently very basic: https://devcenter.heroku.com/articles/nodejs我正在尝试将一个简单的基于 node.js express 的应用程序部署到 heroku,这显然是非常基本的: https ://devcenter.heroku.com/articles/nodejs

Here is my package.json:这是我的 package.json:

{
  "name": "cours-lic3-blois",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "*",
    "ejs": "*",
    "github-flavored-markdown": "*",
    "less-middleware": "*"
  },
  "engines": {
    "node": "0.8.8",
    "npm": "1.1.65"
  }
}

When I git push heroku master I got the following trace:当我git push heroku master时,我得到了以下痕迹:

 -----> Heroku receiving push
 -----> Node.js app detected
 -----> Resolving engine versions
        Using Node.js version: 0.8.8
        Using npm version: 1.1.65
 -----> Fetching Node.js binaries
 -----> Vendoring node into slug
 -----> Installing dependencies with npm
        npm ERR! Error: ENOENT, chmod '/tmp/build_1suuxlhd9s8n6/node_modules/express/bin/express'
        npm ERR! If you need help, you may report this log at:
        npm ERR!     <http://github.com/isaacs/npm/issues>
        npm ERR! or email it to:
        npm ERR!     <npm-@googlegroups.com>

        npm ERR! System Linux 2.6.32-348-ec2
        npm ERR! command "/tmp/node-node-tonf/bin/node" "/tmp/node-npm-NG88/cli.js" "rebuild"
        npm ERR! cwd /tmp/build_1suuxlhd9s8n6
        npm ERR! node -v v0.8.8
        npm ERR! npm -v 1.1.65
        npm ERR! path /tmp/build_1suuxlhd9s8n6/node_modules/express/bin/express
        npm ERR! code ENOENT
        npm ERR! errno 34
        npm ERR!
        npm ERR! Additional logging details can be found in:
        npm ERR!     /tmp/build_1suuxlhd9s8n6/npm-debug.log
        npm ERR! not ok code 0
  !     Failed to rebuild dependencies with npm
  !     Heroku push rejected, failed to compile Node.js app

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

I tried to tweak various versions in my package.json but to no avail.我试图在我的 package.json 中调整各种版本但无济于事。 I am developing on windows and it might be possible this ENOENT issue is due to some filemode issue.我正在 Windows 上开发,这个 ENOENT 问题可能是由于某些文件模式问题引起的。

I got this fixed by:我通过以下方式解决了这个问题:

  • Making sure Procfile is committed into git确保 Procfile 已提交到 git

  • Removing the node_modules/ folder and committing that into git (git rm -r node_modules/)删除 node_modules/ 文件夹并将其提交到 git (git rm -r node_modules/)

Afterwards, I did the git push heroku master then the error disappeared.之后,我做了 git push heroku master 然后错误消失了。

I had this problem, and it was because:我有这个问题,这是因为:

  1. I keep node_modules in version control我将node_modules保留在版本控制中
  2. I had bin in my.gitignore file我在 my.gitignore 文件中有bin

npm was attempting to chmod express/bin/express , but due to my .gitignore this file wasn't in git and thus was not being cloned during the deploy, so it failed. npm试图chmod express/bin/express ,但由于我的.gitignore这个文件不在 git 中,因此在部署期间没有被克隆,所以它失败了。 I didn't notice it because a local npm install would create the bin/express file as usual.我没有注意到它,因为本地npm install 会像往常一样创建bin/express文件。

Removing bin from .gitignore and committing the missing files solved the problem for me..gitignore中删除bin并提交丢失的文件为我解决了这个问题。

Heroku team, could you please consider configuring npm to use npm install --no-bin-links --production by default, or creating an environment variable to let users set that flag. Heroku 团队,您能否考虑将 npm 配置为默认使用npm install --no-bin-links --production ,或者创建一个环境变量让用户设置该标志。 This is a serious bug in node installs.这是节点安装中的一个严重错误。 Removing the bin directory from my.gitignore (as suggested below) enabled me to deploy, but it breaks using git effectively in a cross-platform development environment, requiring an explicit npm rebuild on every git pull where node_modules might have changed.从 my.gitignore 中删除 bin 目录(如下所示)使我能够进行部署,但它会破坏在跨平台开发环境中有效地使用 git,需要在 node_modules 可能已更改的每个 git pull 上进行显式 npm 重建。

NPM best practice is to avoid having node_modules in.gitignore (see http://www.futurealoof.com/posts/nodemodules-in-git.html ). NPM 最佳实践是避免在 .gitignore 中使用 node_modules(请参阅http://www.futurealoof.com/posts/nodemodules-in-git.html )。

I believe --no-bin-links will provide the best of both worlds, enabling deploys of node_modules where the bin directory has been excluded, supporting npm rebuild, but not failing when a bin link is created.我相信--no-bin-links将提供两全其美的优势,允许在 bin 目录被排除的地方部署 node_modules,支持 npm 重建,但在创建 bin 链接时不会失败。

I submitted a pull request here: https://github.com/heroku/heroku-buildpack-nodejs/pull/33我在这里提交了一个拉取请求: https ://github.com/heroku/heroku-buildpack-nodejs/pull/33

Thanks!谢谢!

similar issue was fixed by renaming gruntfile.js to Gruntfile.js通过将 gruntfile.js 重命名为 Gruntfile.js 解决了类似的问题

I had a similar problem a few days ago, I think it was because I imported a module created by me and that was what gave the error;几天前我遇到了类似的问题,我想是因为我导入了一个我创建的模块,这就是错误的原因; I corrected it like this: I called the module "path" const path = require ("path") and then where my module was imported I made a join of the file path const myModule = require (path.join (__ dirname, 'MyModule.js'))我这样更正它:我将模块称为“路径” const path = require ("path") ,然后在我的模块被导入的地方我加入了文件路径const myModule = require (path.join (__ dirname, 'MyModule.js'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM