Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 将NestJSAPI部署到Heroku_Typescript_Heroku_Nestjs - Fatal编程技术网

Typescript 将NestJSAPI部署到Heroku

Typescript 将NestJSAPI部署到Heroku,typescript,heroku,nestjs,Typescript,Heroku,Nestjs,当我将Nestjs rest api部署到heroku时,我没有收到任何错误,但在我手动结束该过程之前,它在一个循环中被卡住了半个多小时 它不停地走 程序文件 web: npm run start:prod package.json { "name": "rest-api", "version": "0.0.1", "description": "", &q

当我将Nestjs rest api部署到heroku时,我没有收到任何错误,但在我手动结束该过程之前,它在一个循环中被卡住了半个多小时

它不停地走

程序文件

web: npm run start:prod
package.json

{
  "name": "rest-api",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "engines": {
    "node": "12.13.1"
  },
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "start":"node dist/src/main.js",
    "prestart:prod": "npm install",
    "start:dist": "node dist/main.js",
    "start:prod": "node dist/main.js",
    "postinstall": "npm run prestart:prod",
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^7.0.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/jwt": "^7.1.0",
    "@nestjs/passport": "^7.1.0",
    "@nestjs/platform-express": "^7.4.2",
    "@nestjs/typeorm": "^7.1.0",
    "@types/bcrypt": "^3.0.0",
    "bcrypt": "^5.0.0",
    "class-transformer": "^0.3.1",
    "class-validator": "^0.12.2",
    "config": "^3.3.1",
    "multer": "^1.4.2",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "pg": "^8.3.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4",
    "typeorm": "^0.2.25"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.0.0",
    "@nestjs/schematics": "^7.0.0",
    "@nestjs/testing": "^7.0.0",
    "@types/express": "^4.17.7",
    "@types/jest": "25.2.3",
    "@types/node": "^13.9.1",
    "@types/supertest": "^2.0.8",
    "@typescript-eslint/eslint-plugin": "3.0.2",
    "@typescript-eslint/parser": "3.0.2",
    "eslint": "7.1.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-plugin-import": "^2.20.1",
    "jest": "26.0.1",
    "prettier": "^1.19.1",
    "supertest": "^4.0.2",
    "ts-jest": "26.1.0",
    "ts-loader": "^6.2.1",
    "ts-node": "^8.6.2",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^3.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

梅因酒店

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const serverConfig = config.get('server')
  const app = await NestFactory.create(AppModule);
  app.enableCors();
  const port = process.env.Port|| 3000
  await app.listen(port);
}
bootstrap();
有没有办法解决这个问题? 我尝试添加一些脚本,如 “heroku后期生成”:“echo Skip在heroku上生成” 但也没用

编辑


问题已经解决了,因为我在config.yml文件中使用了一个变量,heroku出于某种原因一直拒绝它

您在
package.json中对postinstall脚本的配置不正确

"postinstall": "npm run prestart:prod",
"prestart:prod": "npm install",
它所做的是再次触发
npm安装
。 在heroku上,运行install会在安装完成后触发postinstall,包括通过命令手动运行
npm install

所以您运行install,它触发postinstall,它触发另一个安装,等等


我不知道你想用这个脚本完成什么,但因为它实际上没有任何作用,我建议你干脆从package.json中删除它。

我删除了它,但仍然无法工作,我得到了
at=error code=H10 desc=“App crash”method=get path=“/”host=api-prod-nest.herokapp.com request\u id=40cefc3c1-bf44-4cf5-b424-29f2108ecaf4-fwd="77.31.44.244“dyno=connect=service=status=503字节=protocol=https
,我是这样说的:但一切都不起作用。这似乎是一个与你提出的问题无关的问题,可能应该分开讨论question@Ruqayya我认为在
main.ts
中,您应该使用
PORT
而不是
PORT
作为@NatanDeitch,这实际上是另一个错误,谢谢