LoginSignup
2
2

More than 3 years have passed since last update.

NestJSのappをGCPにデプロイしたときに出たエラーの話

Posted at

はじめに

NestCLIで hello world! を表示するnestjsのappの雛形を作成した。ローカルで開くとしっかり表示されるが、GCPにデプロイしてサイトにアクセスすると、500 server errorが出てしまった。

解決策

package.json
{
  "name": "attendance-server",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "engines": {
    "node": ">=8.0.0"
  },
  "main": "dist/main.js",
  "scripts": {
    "prepare": "npm run build",
    "pretest": "npm run build",
    "build": "tsc -p tsconfig.build.json",
    "deploy": "gcloud app deploy",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "start": "node ./dist/main.js",
    "start:dev": "nodemon",
    "start:debug": "nodemon --config nodemon-debug.json",
    "test": "repo-tools test app -- dist/main.js",
    "gcp-build": "npm run build"
  },
  "dependencies": {
    "@nestjs/common": "^7.0.9",
    "@nestjs/core": "^7.0.9",
    "@nestjs/mongoose": "^6.4.0",
    "@nestjs/passport": "^7.0.0",
    "@nestjs/platform-express": "^7.0.0",
    "@nestjs/typeorm": "^7.0.0",
    "express": "^4.17.1",
    "mongoose": "^5.9.11",
    "mysql": "^2.18.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4",
    "typeorm": "^0.2.24"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.0.0",
    "@nestjs/schematics": "^7.0.0",
    "@nestjs/testing": "^7.0.0",
    "@types/express": "^4.17.3",
    "@types/jest": "25.1.4",
    "@types/node": "^13.9.1",
    "@types/supertest": "^2.0.8",
    "@typescript-eslint/eslint-plugin": "^2.23.0",
    "@typescript-eslint/parser": "^2.23.0",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-plugin-import": "^2.20.1",
    "jest": "^25.1.0",
    "prettier": "^1.19.1",
    "supertest": "^4.0.2",
    "ts-jest": "25.2.1",
    "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"
  }
}

上記のようにpackage.jsonを書き直したら治った。 "main"と"script"の中身が大事。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2