AkhileshNS / heroku-deploy

A simple github action that dynamically deploys an app to heroku
MIT License
972 stars 254 forks source link

Deploy NPM Workspaces #146

Open h1sashin opened 1 year ago

h1sashin commented 1 year ago

Hello, I have a problem with deploying npm workspaces/monorepo, I want to deploy ONLY the server file with my NestJS app, but pipeline screams that some packages are not found or types are wrong, how can I "wrap" my server package with files like package-lock.json or tsconfig.base.json? Do I need to dockerize my app? If yes, could someone explain how to do this?

oswaldoacauan commented 6 months ago

For future reference and for anyone that is running a monorepo using NPM workspaces.

You can workaround this issue by using the workspace option inside .npmrc file. This will make all npm commands to respect your workspace option, and that includes the npm ci that is automatically run in Heroku.

If anyone is deploying via Github Actions and using heroku-deploy action you can do something similar to this:

- name: ⬇️ checkout repo
  uses: actions/checkout@v4

- name: 🥁 update .npmrc with workspace option
  run: |
    printf "\nworkspace=\"your-app\"" >> .npmrc
    cat .npmrc
    git config --global user.email "${{secrets.HEROKU_DEPLOYMENT_EMAIL}}"
    git config --global user.name "github-actions[bot]"
    git add -A && git commit -m "updated .npmrc with workspace option"

- name: ♊️ deploy to heroku
  uses: akhileshns/heroku-deploy@v3.12.14
  ...