我在这里遵循了Heroku上node.js的基本入门说明:
https://devcenter.heroku.com/categories/nodejs
这些指令不会告诉您创建.gitignore node_modules,因此暗示应将node_modules检入git。当我在git中包含node_modules时,我的入门应用程序正确运行。
当我遵循以下更高级的示例时:
https://devcenter.heroku.com/articles/realtime-polyglot-app-node-ruby-mongodb-socketio https://github.com/mongolab/tractorpush-server (源)
它指示我将node_modules添加到.gitignore。因此,我从git中删除了node_modules,将其添加到.gitignore中,然后重新部署。这次部署失败,如下所示:
-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.8.2
Using npm version: 1.0.106
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
Error: npm doesn't work with node v0.8.2
Required: node@0.4 || 0.5 || 0.6
at /tmp/node-npm-5iGk/bin/npm-cli.js:57:23
at Object.<anonymous> (/tmp/node-npm-5iGk/bin/npm-cli.js:77:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/tmp/node-npm-5iGk/cli.js:2:1)
at Module._compile (module.js:449:26)
Error: npm doesn't work with node v0.8.2
Required: node@0.4 || 0.5 || 0.6
at /tmp/node-npm-5iGk/bin/npm-cli.js:57:23
at Object.<anonymous> (/tmp/node-npm-5iGk/bin/npm-cli.js:77:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/tmp/node-npm-5iGk/cli.js:2:1)
at Module._compile (module.js:449:26)
Dependencies installed
-----> Discovering process types
Procfile declares types -> mongod, redis, web
-----> Compiled slug size is 5.0MB
-----> Launching... done, v9
运行“ heroku ps”可确认崩溃。好的,没问题,所以我回滚了更改,将node_module添加回git存储库,并将其从.gitignore中删除。但是,即使还原后,在部署时我仍然会收到相同的错误消息,但是现在应用程序再次正常运行。运行“ heroku ps”会告诉我该应用程序正在运行。
所以我的问题是正确的方法是什么?是否包含node_modules?为什么回滚时仍会收到错误消息?我的猜测是git储存库在Heroku方面处于不良状态?
node_modules
Heroku应用。