0

我目前正在尝试在 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是包的 devDependency @mapbox/node-pre-gyp,它本身是bcrypt.js. 这与节点版本有关吗?我目前正在使用node v16.4.0

4

1 回答 1

1

Amplify Hosting 目前支持9.xx版中的所有 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-Amplify-support

于 2021-07-16T16:05:23.257 回答