Search code examples
node.jsnpmbuildnestjs

Nest.js - "Invalid command: start"


This app worked for a long time in docker container and recently it even doesn't launch.

In docker container I've this error:

app  | > [email protected] start:debug /srv/app
app  | > nest start --debug 127.0.0.1:9229 --watch
app  | 
app  | Invalid command: start
app  | See --help for a list of available commands.
app  | npm ERR! code ELIFECYCLE
app  | npm ERR! errno 1
app  | npm ERR! [email protected] start:debug: `nest start --debug 127.0.0.1:9229 --watch`
app  | npm ERR! Exit status 1
app  | npm ERR! 
app  | npm ERR! Failed at the [email protected] start:debug script.
app  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
app  | 
app  | npm ERR! A complete log of this run can be found in:
app  | npm ERR!     /root/.npm/_logs/2022-04-07T13_01_07_426Z-debug.log

If I launch this via terminal on my machine it just doesn't launch without any errors:

/develop/app -> npm run start     (06:57:32 PM)

> [email protected] start
> nest start



/develop/app ->.                  (06:57:39 PM)

My package.json:

{
  "name": "app",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:docker": "docker-compose up --build -V",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug 127.0.0.1:9229 --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": {
    "@hapi/joi": "^17.1.1",
    "@nestjs/common": "^8.0.0",
    "@nestjs/config": "^1.0.1",
    "@nestjs/core": "^8.0.6",
    "@nestjs/microservices": "^8.0.11",
    "@nestjs/platform-express": "^8.0.0",
    "@nestjs/serve-static": "^2.2.2",
    "@nestjs/swagger": "^5.0.9",
    "@nestjs/typeorm": "^8.0.2",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
    "dotenv": "^10.0.0",
    "joi": "^17.4.2",
    "kafkajs": "^1.15.0",
    "libphonenumber-js": "^1.9.38",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.3.0",
    "swagger-ui-express": "^4.1.6",
    "ua-parser-js": "^1.0.2",
    "xlsx": "^0.18.5"
  },
  "devDependencies": {
    "@nestjs/cli": "^5.6.2",
    "@nestjs/schematics": "^8.0.0",
    "@nestjs/testing": "^8.0.0",
    "@types/convert-excel-to-json": "^1.7.1",
    "@types/express": "^4.17.13",
    "@types/jest": "^27.0.1",
    "@types/multer": "^1.4.7",
    "@types/node": "^14.14.31",
    "@types/supertest": "^2.0.10",
    "@types/ua-parser-js": "^0.7.36",
    "@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": "^27.0.6",
    "prettier": "^2.2.1",
    "supertest": "^6.1.3",
    "ts-jest": "^27.0.3",
    "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"
  }
}

My dockerfile:

FROM node:14.17-alpine

# Copy project to the image
WORKDIR /srv/app
RUN mkdir static
COPY . /srv/app

# Install dependencies
RUN npm install

# Build and run the nest project
CMD ["npm", "run", "start:debug"]

My configuration: macOS Monterey 12.3.1 Btw, another developer successfully launching this app. He have a Windows 10 machine.

I repeat: for a very long time everything worked. package.json and Dockerfile haven't changed at all during this time. And it's only recently that it's started to come out.


Solution

  • The @nestjs/cli dev dependency should be up on version 8 with the rest of the @nestjs/ dependencies. @nestjs/cli v5 doesn't have a start command