gpt4 book ai didi

reactjs - 尝试将 NextJS 应用程序部署到 Docker 时捕获错误 `SyntaxError: missing ) after argument list`

转载 作者:行者123 更新时间:2023-12-05 06:09:03 33 4
gpt4 key购买 nike

我有一个带有自定义 Express 服务器的基本 NextJS 设置。

我正在尝试对应用程序进行 Dockerize。这是我的 Dockerfile:

FROM node:alpine

WORKDIR /usr/app

RUN npm install --global pm2

COPY ./package.json ./

RUN yarn docker:build

COPY ./ ./

RUN yarn build

EXPOSE 3000

USER node

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

我的 docker:build 命令是,

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

无论如何,我尝试运行 docker-compose up 并遇到以下错误:

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)

我不知道我在这里做错了什么。

我在一个仓库中简化了我的设置 here .

如有任何帮助,我们将不胜感激。

Github问题

最佳答案

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

next 构建时,它会将编译后的 JavaScript 放入 .next 文件夹中。此外,pm2 接受一个start 命令。

关于reactjs - 尝试将 NextJS 应用程序部署到 Docker 时捕获错误 `SyntaxError: missing ) after argument list`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64938232/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com