我创建了一个nestjs应用程序,现在正在寻找将其部署到Heroku生产环境的最佳方法。
当我尝试按照nest-cli生成的代码部署时,从heroku中得到如下日志:
2018-12-28T08:37:23.881261+00:00 app[api]: Release v1 created by user myemail@gmail.com
2018-12-28T08:37:24.051831+00:00 app[api]: Release v2 created by user myemail@gmail.com
2018-12-28T08:37:23.881261+00:00 app[api]: Initial release by user myemail@gmail.com
2018-12-28T09:00:47.000000+00:00 app[api]: Build started by user myemail@gmail.com
2018-12-28T09:01:37.401065+00:00 heroku[web.1]: Starting process with command `npm start`
2018-12-28T09:01:40.164685+00:00 heroku[web.1]: Process exited with status 1
2018-12-28T09:01:40.205293+00:00 heroku[web.1]: State changed from starting to crashed
2018-12-28T09:01:40.209626+00:00 heroku[web.1]: State changed from crashed to starting
2018-12-28T09:01:40.051608+00:00 app[web.1]:
2018-12-28T09:01:40.051626+00:00 app[web.1]: > nest-app-heroku@0.0.0 start /app
2018-12-28T09:01:40.051628+00:00 app[web.1]: > ts-node -r tsconfig-paths/register src/main.ts
2018-12-28T09:01:40.051630+00:00 app[web.1]:
2018-12-28T09:01:40.055835+00:00 app[web.1]: sh: 1: ts-node: not found
2018-12-28T09:01:40.060789+00:00 app[web.1]: npm ERR! file sh
2018-12-28T09:01:40.061057+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-28T09:01:40.061266+00:00 app[web.1]: npm ERR! errno ENOENT
2018-12-28T09:01:40.061453+00:00 app[web.1]: npm ERR! syscall spawn
2018-12-28T09:01:40.062961+00:00 app[web.1]: npm ERR! nest-app-heroku@0.0.0 start: `ts-node -r tsconfig-paths/register src/main.ts`
2018-12-28T09:01:40.063106+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-12-28T09:01:40.063357+00:00 app[web.1]: npm ERR!
2018-12-28T09:01:40.063536+00:00 app[web.1]: npm ERR! Failed at the nest-app-heroku@0.0.0 start script.
2018-12-28T09:01:40.063679+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-12-28T09:01:40.071632+00:00 app[web.1]:
2018-12-28T09:01:40.071873+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-12-28T09:01:40.072032+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-12-28T09_01_40_065Z-debug.log
2018-12-28T09:01:33.022359+00:00 app[api]: Deploy 9c1f4f41 by user marouen.dbouba@gmail.com
2018-12-28T09:01:33.022359+00:00 app[api]: Release v3 created by user marouen.dbouba@gmail.com
2018-12-28T09:01:33.039917+00:00 app[api]: Scaled to web@1:Free by user marouen.dbouba@gmail.com
2018-12-28T09:01:44.674047+00:00 heroku[web.1]: Starting process with command `npm start`
2018-12-28T09:01:48.017743+00:00 heroku[web.1]: State changed from starting to crashed
2018-12-28T09:01:47.991814+00:00 heroku[web.1]: Process exited with status 1
2018-12-28T09:01:47.850020+00:00 app[web.1]:
2018-12-28T09:01:47.850041+00:00 app[web.1]: > nest-app-heroku@0.0.0 start /app
2018-12-28T09:01:47.850043+00:00 app[web.1]: > ts-node -r tsconfig-paths/register src/main.ts
2018-12-28T09:01:47.850044+00:00 app[web.1]:
2018-12-28T09:01:47.864981+00:00 app[web.1]: sh: 1: ts-node: not found
2018-12-28T09:01:47.880409+00:00 app[web.1]: npm ERR! file sh
我发现Heroku没有安装node-ts。将生成的JS文件本地推送到Heroku可以解决问题吗?还是有更好的解决方案?
这是我的package.json文件:
{
"name": "nest-app-heroku",
"version": "0.0.0",
"description": "description",
"author": "",
"license": "MIT",
"scripts": {
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && tsc",
"start:prod": "node dist/main.js",
"start:hmr": "node dist/server",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json",
"webpack": "webpack --config webpack.config.js"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.2.2",
"typescript": "^3.0.1"
},
"devDependencies": {
"@nestjs/testing": "^5.1.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.1",
"@types/node": "^10.7.1",
"@types/supertest": "^2.0.5",
"jest": "^23.5.0",
"nodemon": "^1.18.3",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"supertest": "^3.1.0",
"ts-jest": "^23.1.3",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "5.11.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-node-externals": "^1.7.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}