Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting `sh: 1: exec: nest: not found` error deploying nestjs to google app engine

I am trying to deploy my nestjs application to google app engine, but I get sh: 1: exec: nest: not found error

my package.json

    "main": "dist/main.js",
    "scripts": {
        "prebuild": "rimraf dist",
        "build": "nest build",
        "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
        "start": "nest start",
        "start:dev": "nest start --watch",
        "start:debug": "nest start --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",
        "gcp-build": "npm run build",
        "ae:deploy": "gcloud app deploy --quiet",
        "ae:browse": "gcloud app browse",
        "@nestjs/cli": "^8.0.0",
    }
       

DockerFile

FROM node:14-alpine

WORKDIR /usr/src/app
ENV NODE_ENV=production

COPY package*.json ./

RUN npm install -g @nestjs/cli@8

RUN npm install

COPY . ./

RUN npm run build

CMD [ "npm", "run", "start:prod" ]

app.yaml

runtime: nodejs14
service: default

instance_class: F1

env_variables:
  NODE_ENV: 'production'

CloudBuild.yaml

steps:
- name: "gcr.io/cloud-builders/docker"
  args:
  - build
  - "--tag=gcr.io/cmor-baas-dev/kafka-connector:latest"
  - "--file=Dockerfile"
  - .  
images:
- "gcr.io/cmor-baas-dev/kafka-connector"
timeout: 1800s

npm run ae:deploy

logs

I think both Dockerfile and CloudBuild.yaml files are ignored (I am new to Google app engine, not sure do we need those files)

Update

Based on here,

All dependencies that you define under the devDependencies field are ignored and do not get installed for your app in App Engine.

So I moved @nestjs/cli to dependencies in my package.json, still same error

like image 876
Reza Avatar asked Oct 25 '25 18:10

Reza


2 Answers

In case someone else came to this post looking for answer:

Two changes are needed:

1- update start script to "start": "node dist/main.js"

2- move @nestjs/cli from devDependency to dependency

Then it starts working

p.s Neither CloudBuild.yaml or Dockerfile is needed

like image 50
Reza Avatar answered Oct 28 '25 07:10

Reza


If you came here looking for a solution because you are trying to deploy nestjs app on render.com and having this same issue, today is your lucky day.

  1. Uninstall @nestjs/cli as devDependency and install dependency.

  2. Set start script to; "start:prod": "node dist/main"

  3. Set node version in package.json as:

    "engines": { "node": "x.x.x"//e.g "18.16.0" }

Then push and deploy on render; it should work.

like image 44
Basil Avatar answered Oct 28 '25 07:10

Basil