我有一个基于next.js框架的小型网站,我想在AWS Elastic Beanstalk上部署它。
我按照这里https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html和这里https://nextjs.org/docs/deployment的入门文档进行操作。然而,next.js网站上的文档并没有深入探讨。
所以我做了以下步骤:
我认为最重要的一行是:
我该如何解决这个问题? 非常感谢。
一些额外的信息: 我的package.json看起来像这样:
我按照这里https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html和这里https://nextjs.org/docs/deployment的入门文档进行操作。然而,next.js网站上的文档并没有深入探讨。
所以我做了以下步骤:
- 在我的项目文件夹中运行
npm run build
- 这将生成.next
文件夹。 - 复制
.next
文件夹内的package.json
文件。 - 打开
.next
文件夹并压缩其内容(使所有文件都在zip的根目录中)。 - 打开AWS管理控制台,选择
创建Web应用程序
并上传zip文件。
Healthstatus: Severe - 100.0 %的请求返回HTTP 5xx错误。
于是我查看了日志,得到了以下信息:Jan 2 19:44:38 ip-172-31-23-147 web: at /var/app/current/node_modules/next/dist/bin/next:27:115
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! code ELIFECYCLE
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! errno 1
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! next-js-website@0.1.3 start: `next start -p $PORT`
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! Exit status 1
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR!
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! Failed at the next-js-website@0.1.3 start script.
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! A complete log of this run can be found in:
Jan 2 19:44:38 ip-172-31-23-147 web: npm ERR! /home/webapp/.npm/_logs/2021-01-02T19_44_38_214Z-debug.log
Jan 2 19:44:38 ip-172-31-23-147 web: > next-js-website@0.1.3 start /var/app/current
Jan 2 19:44:38 ip-172-31-23-147 web: > next start -p $PORT
Jan 2 19:44:38 ip-172-31-23-147 web: Error: Could not find a production build in the '/var/app/current/.next' directory. Try building your app with 'next build' before starting the production server. https://err.sh/vercel/next.js/production-start-no-build-id
Jan 2 19:44:38 ip-172-31-23-147 web: at Server.readBuildId (/var/app/current/node_modules/next/dist/next-server/server/next-server.js:138:355)
Jan 2 19:44:38 ip-172-31-23-147 web: at new Server (/var/app/current/node_modules/next/dist/next-server/server/next-server.js:3:120)
Jan 2 19:44:38 ip-172-31-23-147 web: at createServer (/var/app/current/node_modules/next/dist/server/next.js:2:638)
Jan 2 19:44:38 ip-172-31-23-147 web: at start (/var/app/current/node_modules/next/dist/server/lib/start-server.js:1:323)
Jan 2 19:44:38 ip-172-31-23-147 web: at nextStart (/var/app/current/node_modules/next/dist/cli/next-start.js:19:125)
我认为最重要的一行是:
Could not find a production build in the '/var/app/current/.next' directory. Try building your app with 'next build' before starting the production server. https://err.sh/vercel/next.js/production-start-no-build-id
但正如您在上面看到的那样,我之前已经运行了npm run build
并创建了构建文件夹。
经过一些研究,我发现许多人似乎遇到了类似的问题,但我还没有找到解决方法。我该如何解决这个问题? 非常感谢。
一些额外的信息: 我的package.json看起来像这样:
{
"name": "next-js-website",
"version": "0.1.3",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p $PORT"
},
"engines": {
"node": "12.9.0"
},
"dependencies": {
"aws-sdk": "^2.817.0",
"chart.js": "^2.9.4",
"moment": "^2.29.1",
"moment-timezone": "^0.5.32",
"next": "10.0.4",
"react": "17.0.1",
"react-chartjs-2": "^2.11.1",
"react-device-detect": "^1.15.0",
"react-dom": "17.0.1"
}
}
我的压缩文件看起来像这样:
.env.production
或next.config.js
?或者这些文件会被打包到构建中吗? - Marnix.hohnext.config.js
,请确保将其包含在内。没有它,我会遇到错误。 - thetaPC