Stack Exchange
sh: 1: rimraf not found - Cloud Foundry & Node.js
I want to deploy my node.js app to CloudFoundry. Here are the initial build & dependencies scripts within my package.json:
  "scripts": {
    "build": "rimraf dist && tsc",
    "watch": "nodemon lib/server.js",
    "start": "npm run build && node dist/src/index.js",
    "start:dev": "ts-node src/index.ts",
    "db:start": "docker run --rm --name bb-ads -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres:12-alpine",
    "test": "mocha --recursive",
    "test:coverage": "c8 --check-coverage --lines 95 --functions 95 --branches 95 npm test",
    "lint": "eslint ."
  },
  "repository": {
    "type": "git",
    "url": "https://github.tools.sap/cloud-curriculum/exercise-code-nodejs.git"
  },
  "devDependencies": {
    "@types/cfenv": "^1.2.2",
    "@types/express": "^4.17.17",
    "@types/mocha": "^9.1.1",
    "@types/node": "^16.18.8",
    "@types/pg": "^8.10.2",
    "@types/sinon": "^10.0.13",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.45.0",
    "@typescript-eslint/parser": "^5.45.0",
    "c8": "^7.12.0",
    "eslint": "^8.6.0",
    "mocha": "^9.1.3",
    "nodemon": "^2.0.15",
    "rimraf": "^3.0.2",
    "sinon": "^12.0.1",
    "supertest": "^6.2.1",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.3"
  },
  "engines": {
    "node": ">=16"
  },
  "dependencies": {
    "axios": "^1.2.2",
    "cfenv": "^1.2.4",
    "express": "^4.17.2",
    "pg": "^8.11.0",
    "winston": "^3.8.2",
    "zod": "^3.21.4"
  },

When I deploy the app with this config the error ERR sh: 1: rimraf: not found occurs.
Based on these posts (Node.js app runs locally but fails on docker (sh: 1: rimraf: not found) and sh: 1: rimraf: not found whenever I run npm run build within vagrant installed on Windows 10 I did the following changes:

Installed rimraf globally (npm install --global rimraf) This failed because I wasn't authorized to change the filde

Added "rimraf": "./node_modules/rimraf/bin.js" to my package.json


Current package.json:
  "scripts": {
    "build": "npm run rimraf && tsc",
    "watch": "nodemon lib/server.js",
    "start": "npm run build && node dist/src/index.js",
    "start:dev": "ts-node src/index.ts",
    "db:start": "docker run --rm --name bb-ads -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres:12-alpine",
    "test": "mocha --recursive",
    "test:coverage": "c8 --check-coverage --lines 95 --functions 95 --branches 95 npm test",
    "lint": "eslint .",
    "rimraf": "./node_modules/rimraf/bin.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.tools.sap/cloud-curriculum/exercise-code-nodejs.git"
  },
  "devDependencies": {
    "@types/cfenv": "^1.2.2",
    "@types/express": "^4.17.17",
    "@types/mocha": "^9.1.1",
    "@types/node": "^16.18.8",
    "@types/pg": "^8.10.2",
    "@types/sinon": "^10.0.13",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.45.0",
    "@typescript-eslint/parser": "^5.45.0",
    "c8": "^7.12.0",
    "eslint": "^8.6.0",
    "mocha": "^9.1.3",
    "nodemon": "^2.0.15",
    "rimraf": "^3.0.2",
    "sinon": "^12.0.1",
    "supertest": "^6.2.1",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.3"
  },
  "engines": {
    "node": ">=16"
  },
  "dependencies": {
    "axios": "^1.2.2",
    "cfenv": "^1.2.4",
    "express": "^4.17.2",
    "pg": "^8.11.0",
    "winston": "^3.8.2",
    "zod": "^3.21.4"
  },

Now I get the following error: ERR sh: 1: ./node_modules/rimraf/bin.js: not found
Some general questions:

For what do we need the rimraf module?
It seems that rimraf <PATH> deletes the file with the corresponding path


Answering on your questions:

rimraf is the same for rm -rf in linux
It's seems like you make installation via npm install --production, when your rimraf in dev dependencies.

Possible solutions:

If you build your own docker image, make a multi stage build(https://docs.docker.com/build/building/multi-stage/)
Move rimraf package from devDependencies to dependencies

