skip to Main Content

I’m new to next.js and react. I have created a simple application and would like to serve it using pm2 and Apache.

When I run npm run dev in the folder of the next project, the server starts and I can see my application on port 3000 of localhost.

However, when pm2 attempts to run the application (I have set it to run on server boot), I get the following error in the pm2 logs:

SyntaxError: Unexpected token '<'
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)
    at async link (node:internal/modules/esm/module_job:67:21)

node --version is v16.19.0
npm --version is 8.19.3

Can someone help me to fix this issue? I don’t understand why it is happening at the moment.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed it. I had neglected to build the project with npm run build. Once I'd done that, pm2 worked as desired.


  2. Without providing more information and context, it will be difficult to diagnose exactly what is going wrong. If you want good answers, you need to list out a more comprehensive list of things you’ve tried and information about how you are setting up nextjs with pm2.

    But right now, the character is your best clue. "<" hints at the problem likely being that html markup is being loaded somewhere it shouldn’t be.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search