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

我正在尝试将一个简单的node.js基于expression式的应用程序部署到heroku,这显然是非常基本的: https : //devcenter.heroku.com/articles/nodejs

这是我的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" } } 

当我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' 

我试图调整我的package.json中的各种版本,但无济于事。 我在Windows上开发,这可能是因为一些文件模式问题。

我通过以下方式修复

  • 确保Procfile已被提交到git

  • 删除node_modules /文件夹并将其提交到git(git rm -r node_modules /)

之后,我做了git push heroku master然后错误消失了。

我有这个问题,这是因为:

  1. 我保持版本控制node_modules
  2. 我在我的.gitignore文件中有bin

npm试图chmod express/bin/express ,但由于我的.gitignore这个文件不在git中,因此在部署期间没有被克隆,所以失败了。 我没有注意到它,因为本地npm安装将像往常一样创buildbin/express文件。

.gitignore删除bin并提交丢失的文件为我解决了这个问题。

Heroku团队,请你考虑configurationnpm默认使用npm install --no-bin-links --production ,或者创build一个环境variables让用户设置该标志。 这是节点安装中的一个严重错误。 从我的.gitignore中删除bin目录(如下所示)使我能够部署,但是它在跨平台开发环境中有效地使用git,需要在node_modules可能已经改变的每个git pull上进行显式的npm重build。

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

我相信--no-bin-links将提供两全其美的function,能够部署bin目录已被排除的node_modules,支持npm重build,但是在创buildbin链接时不会失败。

我在这里提交了一个请求: https : //github.com/heroku/heroku-buildpack-nodejs/pull/33

谢谢!

通过将gruntfile.js重命名为Gruntfile.js来解决类似的问题