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/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

解决方法

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/

注意:当最低支持版本发生变化时会更新。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...