生产中部署在 Elastic Beanstalk 上的 NextJs 出现错误

问题描述 投票:0回答:1

我在 AWS Elastic Beanstalk 上部署了 NextJs (v14.1.0) 应用程序。该项目使用 AWS Codebuild (buildspec.yml) 进行部署。它工作得很好,然后我开始在 Chrome 开发控制台中收到 500 内部错误响应。这是在没有对应用程序或环境进行任何更改的情况下发生的。 这只发生在生产版本中。

在浏览器中,当我导航到部署应用程序的 URL 时,我得到以下信息: Screenshot of chrome developer console logs

在服务器上,

web.stdout.log
日志文件中显示以下错误。

Apr 12 14:57:06 web[27070]: TypeError: C is not a function
Apr 12 14:57:06 web[27070]:    at rW (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:10505)
Apr 12 14:57:06 web[27070]:    at runNextTicks (node:internal/process/task_queues:60:5)
Apr 12 14:57:06 web[27070]:    at listOnTimeout (node:internal/timers:538:9)
Apr 12 14:57:06 web[27070]:    at process.processTimers (node:internal/timers:512:7)
Apr 12 14:57:06 web[27070]:    at async /var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9396
Apr 12 14:57:06 web[27070]:    at async Promise.all (index 0)
Apr 12 14:57:06 web[27070]:    at async rW (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9204)
Apr 12 14:57:06 web[27070]:    at async /var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9396
Apr 12 14:57:06 web[27070]:    at async Promise.all (index 0)
Apr 12 14:57:06 web[27070]:    at async rW (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9204) {
Apr 12 14:57:06 web[27070]:  digest: '4228333707'
Apr 12 14:57:06 web[27070]: }
Apr 12 14:57:06 web[27070]: TypeError: C is not a function
Apr 12 14:57:06 web[27070]:    at rW (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:10505)
Apr 12 14:57:06 web[27070]:    at runNextTicks (node:internal/process/task_queues:60:5)
Apr 12 14:57:06 web[27070]:    at listOnTimeout (node:internal/timers:538:9)
Apr 12 14:57:06 web[27070]:    at process.processTimers (node:internal/timers:512:7)
Apr 12 14:57:06 web[27070]:    at async /var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9396
Apr 12 14:57:06 web[27070]:    at async Promise.all (index 0)
Apr 12 14:57:06 web[27070]:    at async rW (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9204)
Apr 12 14:57:06 web[27070]:    at async /var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9396
Apr 12 14:57:06 web[27070]:    at async Promise.all (index 0)
Apr 12 14:57:06 web[27070]:    at async rW (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:9204) {
Apr 12 14:57:06 web[27070]:  digest: '4228333707'
Apr 12 14:57:06 web[27070]: }
Apr 12 14:57:06 web[27070]: TypeError: s is not a function
Apr 12 14:57:06 web[27070]:    at /var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:13:2748
Apr 12 14:57:06 web[27070]:    at eh (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134795)
Apr 12 14:57:06 web[27070]:    at e (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137680)
Apr 12 14:57:06 web[27070]:    at ek (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138154)
Apr 12 14:57:06 web[27070]:    at Array.toJSON (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135764)
Apr 12 14:57:06 web[27070]:    at stringify (<anonymous>)
Apr 12 14:57:06 web[27070]:    at eR (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142228)
Apr 12 14:57:06 web[27070]:    at eE (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142707)
Apr 12 14:57:06 web[27070]:    at Timeout._onTimeout (/var/app/current/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135484)
Apr 12 14:57:06 web[27070]:    at listOnTimeout (node:internal/timers:569:17) {
Apr 12 14:57:06 web[27070]:  digest: '2260024538'
Apr 12 14:57:06 web[27070]: }
Apr 12 14:57:06 web[27070]: [Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
Apr 12 14:57:06 web[27070]:  digest: '2260024538'
Apr 12 14:57:06 web[27070]: }
Apr 12 14:57:06 web[27070]: ⨯ [Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
Apr 12 14:57:06 web[27070]:  digest: '2260024538'
Apr 12 14:57:06 web[27070]: }

有趣的是,我有一些 API 路由,如果我在浏览器中导航到它们,它们会返回数据,没有任何错误,但如果我转到应用程序目录中的路由/页面,则会失败。

示例

版本

  • nextjs:14.1.0
  • 反应/反应-dom:18.2.0
  • 节点:18.18.2
  • npm:9.8.1

为了解决这个问题,我尝试:

  1. 从 codebuild 下载有问题的构建,并尝试在本地使用
    npm run start
    命令运行它,并得到相同的错误。
  2. 恢复到应用程序的旧版本,会发生相同的错误。
  3. 在本地创建生产版本,但我遇到没有错误或问题(问题似乎只发生在生产版本上)。
  4. 我确保版本在我的本地计算机上,代码构建和ElasticBeanstalk环境相同。

这是我用来构建生产项目的

buildspec.yml

version: 0.2

cache:
  paths:
    - 'node_modules/**/*' # Cache `node_modules` for faster `yarn` or `npm i`
    - '.next/cache/**/*' # Cache Next.js for faster application rebuilds

phases:
  install:
    on-failure: ABORT 
    # runtime-versions:
    #   nodejs: 18.18.x
    commands:
      # Installing the same version on the ElasticBeanStalk instance  
      - n 18.18.2
      - node --version
      - npm --version
      - npm install
  build:
    on-failure: ABORT
    commands:
      - node --version
      - npm run build
  post_build:
    on-failure: ABORT
    commands:
      # Copying only the files we need to the dist folder because 
      # that is used as our base directory for the artifact
      - mkdir dist/
      - cp -r .next dist/
      - cp -r .ebextensions dist/
      - cp package.json Procfile .env.production dist/

artifacts:
  files:
    - '**/*'
  base-directory: dist
reactjs next.js amazon-elastic-beanstalk aws-codebuild
1个回答
0
投票

因此,AWS Elastic Beanstalk 似乎更新了其环境中的节点版本或其他一些依赖项,并且因为我没有将本地

package-lock.json
推送到服务器,所以与某些依赖项和其他依赖项的依赖项存在一些不匹配。

© www.soinside.com 2019 - 2024. All rights reserved.