1

I have nestjs app that works fine in development mode, but when I deploy it to DigitalOcean I have an error:

[2025-08-19 00:04:35] │ sh: 1: nest: not found

When I change NODE_ENV in environment variables from production to development then it works, but I dont think it is the proper solution. Also, here (getting `sh: 1: exec: nest: not found` error deploying nestjs to google app engine) the user suggested to move @nestjs/cli from dev-dependencies to dependencies and that solved my problem even with NODE_ENV=production. Is that a proper workaround? These are my scripts:

  "scripts": {
    "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/src/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"
  },

BUT, I have other, much larger nestsjs app and here the problem is similar with the difference that from the very start application was correctly deploying with NODE_ENV=production and @nestjs/cli in dev-dependencies. Now I did a huge merge request and unfortunately I have sh: 1: nest: not found as well here :( Here:

  • when I change NODE_ENV to development, then app build ssuccessfully
  • when I move @nestjs/cli to dev-dependencies then I have the same error Cannot find namespace 'Express'

What is the proper solution? Are some of above practices not recommended?

1 Answer 1

2

Well you can move @nestjs/cli to dependencies, this is one of many workaround. Based on the documentation of buildpack which digitalocean apps uses to automatically detect the tech stack and build container images, prunes devDependencies when NODE_ENV is set to production.

Setting to development is not recommended as you may be using some environment dependent logic. For example, I disable instrumentation services like sentry on development (detected by NODE_ENV). But you can set one of environment flags to trigger buildpack to not prune them while keeping @nestjs/cli in the devDependencies.

  • Setting environment variable NPM_CONFIG_PRODUCTION=false if you’re using npm.
  • Setting environment variable PNPM_SKIP_PRUNING=true if you’re using pnpm.
  • Setting environment variable YARN_PRODUCTION=false if you’re using Yarn v1.
  • Setting environment variable YARN2_SKIP_PRUNING=true if you’re using Yarn v2 and above.

The downside of this approach is that it will not prune other devDependencies like @nestjs/testing, jest, and so on.

Ref: https://docs.digitalocean.com/products/app-platform/reference/buildpacks/nodejs/#skip-pruning

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.