Next.js应用程序在Vercel上成功部署,但在Amplify上失败



我目前正试图在AWS Amplify上托管我的next.js应用程序,但每次都失败了。我正在使用Git CI/CD管道。当同一个应用程序部署在Vercel上时,它只需60秒就部署好了,而且它还能工作。这是我得到的错误:

Starting SSR Build...
2021-07-15T17:21:36.050Z [ERROR]: Error: 'Command failed with exit code 1: node_modules/.bin/next build',
command: 'node_modules/.bin/next build',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: 'info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5n' +
'info  - Checking validity of types...n' +
'info  - Creating an optimized production build...',
stderr: 'Failed to compile.n' +
'n' +
"ModuleNotFoundError: Module not found: Error: Can't resolve 'mock-aws-s3' in '/<project_location>/node_modules/@mapbox/node-pre-gyp/lib/util'n" +
'n' +
'n' +
'> Build error occurredn' +
'Error: > Build failed because of webpack errorsn' +
'    at /<project_location>/node_modules/next/dist/build/index.js:15:924n' +
'    at async Span.traceAsyncFn (/<project_location>/node_modules/next/dist/telemetry/trace/trace.js:6:584)',
failed: true,
timedOut: false,
isCanceled: false,
Terminating logging...

编辑:这是package.json文件

{
"name": "laturnaorders",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"axios": "^0.21.1",
"bcrypt": "^5.0.1",
"bootstrap": "5.0.2",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.13.2",
"next": "11.0.1",
"next-connect": "^0.10.1",
"react": "17.0.2",
"react-bootstrap": "^2.0.0-beta.2",
"react-dom": "17.0.2",
"react-select": "^4.3.1",
"sass": "^1.35.2"
},
"devDependencies": {
"eslint": "7.30.0",
"eslint-config-next": "11.0.1"
}
}

编辑2:我查了一下,似乎mock-aws-s3@mapbox/node-pre-gyp包的devDependency,它本身就是bcrypt.js的dependency。这与节点版本有关吗?我目前正在使用node v16.4.0

Amplify Hosting目前支持9.x.x版本中的所有Next.js功能,包括SSR API路由、动态页面和自动预渲染。

如果您在SSR页面上遇到构建错误或503,请检查您的版本。在某些情况下,降级到v10.2将有助于解决这些错误。

https://aws.amazon.com/about-aws/whats-new/2021/05/aws-amplify-hosting-announces-server-side-rendering-support-for-next-js-web-apps/


编辑:

当前版本支持概述如下-https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#ssr-放大支持

截至2022年9月,由于中间件的原因,我在Amplify上尝试了奇怪的构建失败。这种情况在Vercel不会发生。

删除您的中间件代码并尝试重新部署,这将修复错误。

当然,您必须为中间件功能找到一个变通方法,但这些都是Amplify目前的局限性。

相关内容

最新更新