Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot deploy correctly NestJS on Google App Engine

I'm trying to deploy my Nest.js on Google App Engine but it cannot be deployed successfully...

Reproduce:

nest new my-project

In src/main.ts

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

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(process.env.PORT || 8080);
}
bootstrap();

In package.json

{
    "name": "nest-gcloud-test",
    "version": "0.0.1",
    "description": "",
    "author": "",
    "private": true,
    "license": "UNLICENSED",
    "main": "dist/main.js",
    "scripts": {
        "prebuild": "rimraf dist",
        "build": "nest build",
        "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
        "start": "npm run start:dev",
        "start:dev": "node dist/main --watch",
        "start:debug": "node dist/main --debug --watch",
        "start:prod": "node dist/main",
        "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.6.13",
        "@nestjs/core": "^7.6.13",
        "@nestjs/platform-express": "^7.6.13",
        "reflect-metadata": "^0.1.13",
        "rimraf": "^3.0.2",
        "rxjs": "^6.6.6"
    },
    "devDependencies": {
        "@nestjs/cli": "^7.5.6",
        "@nestjs/schematics": "^7.2.7",
        "@nestjs/testing": "^7.6.13",
        "@types/express": "^4.17.11",
        "@types/jest": "^26.0.20",
        "@types/node": "^14.14.31",
        "@types/supertest": "^2.0.10",
        "@typescript-eslint/eslint-plugin": "^4.15.2",
        "@typescript-eslint/parser": "^4.15.2",
        "eslint": "^7.20.0",
        "eslint-config-prettier": "^8.1.0",
        "eslint-plugin-prettier": "^3.3.1",
        "jest": "^26.6.3",
        "prettier": "^2.2.1",
        "supertest": "^6.1.3",
        "ts-jest": "^26.5.2",
        "ts-loader": "^8.0.17",
        "ts-node": "^9.1.1",
        "tsconfig-paths": "^3.9.0",
        "typescript": "^4.1.5"
    },
    "jest": {
        "moduleFileExtensions": [
            "js",
            "json",
            "ts"
        ],
        "rootDir": "src",
        "testRegex": ".*\\.spec\\.ts$",
        "transform": {
            "^.+\\.(t|j)s$": "ts-jest"
        },
        "collectCoverageFrom": [
            "**/*.(t|j)s"
        ],
        "coverageDirectory": "../coverage",
        "testEnvironment": "node"
    }
}

In app.yaml

runtime: nodejs12

and deploy

gcloud app deploy

After a while the GAE log shows that the Nest application successfully started but GAE shutdowns immediately with the message:

[start] 2021/03/24 20:31:36.643972 No entrypoint specified, using default entrypoint: /serve
[start] 2021/03/24 20:31:36.647170 Starting app
[start] 2021/03/24 20:31:36.647513 Executing: /bin/sh -c exec /serve
[start] 2021/03/24 20:31:36.658103 Waiting for network connection open. Subject:"app/invalid" Address:127.0.0.1:8080
[start] 2021/03/24 20:31:36.660574 Waiting for network connection open. Subject:"app/valid" Address:127.0.0.1:8081
[serve] 2021/03/24 20:31:36.682824 Serve started.
[serve] 2021/03/24 20:31:36.683836 Args: {runtimeLanguage:nodejs runtimeName:nodejs12 memoryMB:256 positional:[]}
[serve] 2021/03/24 20:31:36.686634 Running /bin/sh -c exec npm run start:dev

> [email protected] start:dev /workspace
> node dist/main --watch

[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[NestFactory] [39m[32mStarting Nest application...[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[InstanceLoader] [39m[32mAppModule dependencies initialized[39m[38;5;3m +45ms[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[RoutesResolver] [39m[32mAppController {}:[39m[38;5;3m +6ms[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[RouterExplorer] [39m[32mMapped {, GET} route[39m[38;5;3m +3ms[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[NestApplication] [39m[32mNest application successfully started[39m[38;5;3m +2ms[39m
[start] 2021/03/24 20:32:53.970253 Quitting on terminated signal
[start] 2021/03/24 20:32:53.970940 Start program failed: failed to detect app after start: ForAppStart(): [aborted, context canceled. subject:"app/invalid" Timeout:30m0s, attempts:120069 aborted, context canceled. subject:"app/valid" Timeout:30m0s, attempts:120115]

No error logs on stderr.


However I can successfully deploy a simple http server as follows:

app.js

const http = require('http');

const server = http.createServer((req, res) => {
    res.end(`Hello World\n`);
});

server.listen(process.env.PORT || 8080, () => {
    console.log('app started');
});

app.yaml

runtime: nodejs12

package.json

{
    "name": "appengine",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "start": "node app.js",
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC"
}

Run gcloud app deploy successfully and no problems.


Any helps appreciated.

Solution

Add "gcp-build": "npm run build" to package.json

Then it's now working fine without any problems.

like image 812
Blizard998 Avatar asked Oct 24 '25 00:10

Blizard998


1 Answers

Solution Add "gcp-build": "npm run build" to package.json

Then it's now working fine without any problems.

like image 99
Blizard998 Avatar answered Oct 25 '25 16:10

Blizard998



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!