1

I'm working on a Next.js project, and I am trying to use Github Actions for CI/CD. I am using a DigitalOcean droplet and it is able to build the app easily by doing manually. But I'm not sure why this is not happening on GitHub action.

Here is the problem, enter image description here

Error in text format.

err: npm WARN EBADENGINE Unsupported engine {
err: npm WARN EBADENGINE   package: 'next@13.3.2',
err: npm WARN EBADENGINE   required: { node: '>=16.8.0' },
err: npm WARN EBADENGINE   current: { node: 'v12.***.9', npm: '8.5.1' }
err: npm WARN EBADENGINE }
out: up to date, audited 21 packages in 828ms
out: 3 packages are looking for funding
out:   run `npm fund` for details
out: found 0 vulnerabilities
out: > build
out: > next build
err: /var/www/frontend-test/node_modules/next/dist/build/index.js:394
err:                     ...pageKeys.app ?? []
err:                                      ^
err: SyntaxError: Unexpected token '?'
err:     at wrapSafe (internal/modules/cjs/loader.js:915:16)
err:     at Module._compile (internal/modules/cjs/loader.js:963:27)
err:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
err:     at Module.load (internal/modules/cjs/loader.js:863:32)
err:     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
err:     at Module.require (internal/modules/cjs/loader.js:887:19)
err:     at require (internal/modules/cjs/helpers.js:74:18)
err:     at Object.<anonymous> (/var/www/frontend-test/node_modules/next/dist/cli/next-build.js:15:55)
err:     at Module._compile (internal/modules/cjs/loader.js:999:30)
err:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
out: Use --update-env to update environment variables
out: [PM2] Applying action reloadProcessId on app [frontend-test](ids: [ 0 ])
out: [PM2] [frontend-test](0) ✓
==============================================
✅ Successfully executed commands to all host.
==============================================

My server is using latest Node. enter image description here

The steps when performed manually. enter image description here enter image description here

Npm and node version on server. enter image description here

This is the content of my YAML file.

    on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Dependencies
        run: npm install
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18.x"
      - name: Build
        run: npm run build
      - name: Deploy to Server
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          port: ${{ secrets.PORT }}
          key: ${{ secrets.SSHKEY }}
          script: |
            cd /var/www/frontend-test
            git fetch
            npm install
            npm run build
            pm2 reload frontend-test

Does anyone know what might be causing this issue, and how I can fix it?

nisnym
  • 31
  • 10
  • 1
    Why are you ignoring `EBADENGINE`? That should make it pretty clear why null coalescing isn't going to work - you're not using the latest Node _everywhere_. – jonrsharpe May 02 '23 at 19:01
  • I am new to this and not sure how to fix the EBADENGINE error. Can you please guide me a little about how to fix it? I'm running latest node version on server. – nisnym May 03 '23 at 04:45
  • Share your codes and error messages in the plain text format – Farkhod Abdukodirov May 03 '23 at 05:23
  • @FarkhodAbdukodirov I have added the error in the post. It just a simple starter of Next.js. I'm trying to set up a pipeline for my Next.js project using GitHub Actions so that any changes merged to the main branch are automatically deployed to my DigitalOcean droplet. – nisnym May 03 '23 at 07:03
  • The `appleboy/ssh-action@master` is the one running the `npm` commands on your server. Why? An action should do one thing. But if you say running the same actions manually on the server works, show how you do so. – CodeCaster May 03 '23 at 07:12
  • @CodeCaster I understand that an action should ideally do one thing, but I'm not sure. Actually I'm following this resource - https://github.com/geekyshow1/GeekyShowsNotes/blob/main/nginx/Deploy_NextJS_Nginx.md – nisnym May 03 '23 at 07:26
  • @nisnym: Please run the same sequence of commands as in your SSH script above and add its output in your question. Please do include the node and nextjs versions too. Apparently, the error is coming from the final `dist` artifacts. Did you try cleaning it first before building? Please do that and add its result in your question also if the error is still there. Thanks! – Azeem May 03 '23 at 08:16
  • @Azeem I added the steps in the question. I am using Node v18 and npm 9.5.1. I'm new to this can you please guide me a little bit about how to do the changes in dist artifacts. I did clean after building. – nisnym May 04 '23 at 06:45
  • @nisnym: In your workflow, while SSHing add `node --version` as the first command under `script` and see if that's also using the latest node version. – Azeem May 04 '23 at 06:59
  • @Azeem looks like it is using v 12.. "out: v12.***.9" . I'm not sure how? – nisnym May 04 '23 at 08:02
  • @nisnym: Good. That's the problem with SSH. The user profiles that may have shell configuration are not sourced. Please verify if you have both versions installed. You might have to configure the path of the latest version in the `script` before running those commands. – Azeem May 04 '23 at 08:06
  • @Azeem: so it is something like both of the versions are installed on the server and causing this problem. Can you please tell me the steps or any ref to follow to do this. Thank you so much. – nisnym May 04 '23 at 08:21
  • @nisnym: Please see this [thread](https://stackoverflow.com/questions/76026185/how-to-configure-pm2-to-trigger-from-github-action). – Azeem May 04 '23 at 10:02

0 Answers0