Catching error `SyntaxError: missing ) after argument list` when trying to deploy NextJS app to Docker


I have a basic NextJS setup with a custom Express server.

I’m trying to Dockerize the app. Here is my Dockerfile:

FROM node:alpine

WORKDIR /usr/app

RUN npm install --global pm2

COPY ./package.json ./

RUN yarn docker:build

COPY ./ ./

RUN yarn build


USER node

CMD [ "pm2-runtime", "yarn", "dev" ]

My docker:build command is,

rm -rf node_modules && rm -rf yarn.lock yarn && yarn

Anyway, I try to run docker-compose up and I run into the below error:

nextjs_1  | /opt/yarn-v1.22.5/bin/yarn:2
nextjs_1  | argv0=$(echo "$0" | sed -e 's,\,/,g')
nextjs_1  |         ^^^^
nextjs_1  | SyntaxError: missing ) after argument list
nextjs_1  |     at wrapSafe (node:internal/modules/cjs/loader:1018:16)
nextjs_1  |     at Module._compile (node:internal/modules/cjs/loader:1066:27)
nextjs_1  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)

I have no idea what I’m doing wrong here.

I’ve simplified my setup in a repo here.

Any help would be appreciated.

Github issue


diff --git a/Dockerfile b/Dockerfile
index 658452d..8e2fe06 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -28,4 +28,4 @@ EXPOSE 3000
 USER node
 # Run npm start script when container starts
-CMD [ "pm2-runtime", "yarn", "dev" ]
 No newline at end of file
+CMD [ "pm2-runtime", "start", ".next/production-server/server.js" ]
/usr/app # pm2-runtime start .next/production-server/server.js 
2020-11-21T05:51:18: PM2 log: Launching in no daemon mode
2020-11-21T05:51:18: PM2 log: App [server:0] starting in -fork mode-
2020-11-21T05:51:18: PM2 log: App [server:0] online
event - compiled successfully
App listening on port 3000

When next builds, it drops the compiled JavaScript into .next folder. Additionally, pm2 takes a start command.

Leave a Reply

Your email address will not be published. Required fields are marked *