我遵循了Heroku上Node.js的基本入门说明:
https://devcenter.heroku.com/categories/nodejs
这些指令并没有告诉你创建一个.gitignore node_modules,因此意味着node_modules文件夹应该签入Git。当我在Git存储库中包含node_modules时,我的启动应用程序正常运行。
当我遵循更高级的例子在:
用Node.js, Ruby, MongoDB和Socket构建实时,多语言应用程序。IO 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 ?为什么回滚时仍然会得到错误消息?我猜Heroku这边的Git仓库状态很差。