Tuesday, August 30, 2022

[SOLVED] failed to load next.config.js when building using github action

Issue

I am using simple ssh deploy action and i have a bash script to build and restart pm2 frontend process.

It's working fine when I run it directly run the script through the ec2 instance but gives error when building through the github action

below is the generated error

It says Failed to load next.config.js but its there, I've printed out pwd to make sure its the correcy directory. But still the same error

  • Node -> 14.17.0
  • Next -> 12.0.8
  • npm -> 6.14.3
out: /home/***/elfswap/elfswap-frontend
out: 
out: > fe-elf@ build /home/***/elfswap/elfswap-frontend
out: > next build
out: 
err: error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
err: 
err: > Build error occurred
err: Error: Not supported
err:     at Object.loadConfig [as default] (/home/***/elfswap/elfswap-frontend/node_modules/next/dist/server/config.js:413:78)
#!/bin/bash
cd /home/ubuntu/project/frontend
git pull origin master
echo "$(pwd)"
npm run build
pm2 restart frontend

Solution

Looking back at it with a fresh mind, figured out the problem.

I already knew that remote ssh doesn't load the bash profile, but node command was working fine so i didn't look much further.

but after echoing node version in the bash script, found out it was using version 8.. from /usr/local/bin not the one installed through nvm.

So to make it work, I removed npm, node binaries from /usr/local/bin and replaced those with symbolic links from nvm version directory.

Now its working fine.



Answered By - Manish Singh
Answer Checked By - David Goodson (WPSolving Volunteer)