我目前正在尝试在 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/webpack5\n' +
'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 occurred\n' +
'Error: > Build failed because of webpack errors\n' +
' at /<project_location>/node_modules/next/dist/build/index.js:15:924\n' +
' 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
的依赖。
这与节点版本有关吗?我目前正在使用 node v16.4.0
答案 0 :(得分:1)
Amplify Hosting 目前支持 9.x.x 版本中的所有 Next.js 功能,包括 SSR API 路由、动态页面和自动预渲染。
如果您在 SSR 页面上遇到构建错误或 503,请检查您的版本。在某些情况下,降级到 v10.2 将有助于解决这些错误。
注意:当最低支持版本发生变化时会更新。