Question

How do you use Node.js devDependencies in the App Platform builds?

Posted October 7, 2020 2.3k views
Node.jsDigitalOcean App Platform

How do you use Node.js devDependencies in the App Platform builds? Heroku automatically installs both the dependencies and devDependencies for the app build and then removes the devDependencies after the build is complete. This ensures that you’re only including the minimum required dependencies in production.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
5 answers

👋 @Rowno

Including dev dependencies is a good idea and I’ve created a ticket with the team to include this and clear out the dev deps after build to only include necessary deps for production.

For now a workaround is to customize your build command to something like:

npm install --only=dev && npm run build && npm prune --production

This will install the devDependencies (dependencies have already been installed) then run the build, finally will remove the devDependencies.

I was able to resolve the issue by using npm install --production=false, then build.

I resolve with this command.

  1. Install all dependency (prod and dev)
  2. Clean build folder
  3. Build API
  4. Clean and install production node modules
"build:digitalOcean": "yarn install --production=false && rimraf dist && yarn build && yarn install --production --frozen-lockfile"

I share my package script config

"scripts": {
    "build:digitalOcean": "yarn install --production=false && rimraf dist && yarn build && yarn install --production --frozen-lockfile",
    "build": "babel src --out-dir dist",
    "dev": "nodemon --exec yarn restart",
    "restart": "rimraf dist && yarn build && yarn start",
    "start": "node dist/index.js"
  }