我在 AWS Elastic Beanstalk 上部署了 NextJs (v14.1.0) 应用程序。该项目使用 AWS Codebuild (buildspec.yml) 进行部署。它工作得很好,然后我开始在 Chrome 开发控制台中收到 500 内部错误响应。这是在没有对应用程序或环境进行任何更改的情况下发生的。 这只发生在生产版本中。
在浏览器中,当我导航到部署应用程序的 URL 时,我得到以下信息:
在服务器上,
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 路由,如果我在浏览器中导航到它们,它们会返回数据,没有任何错误,但如果我转到应用程序目录中的路由/页面,则会失败。
示例
版本
为了解决这个问题,我尝试:
npm run start
命令运行它,并得到相同的错误。这是我用来构建生产项目的
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
因此,AWS Elastic Beanstalk 似乎更新了其环境中的节点版本或其他一些依赖项,并且因为我没有将本地
package-lock.json
推送到服务器,所以与某些依赖项和其他依赖项的依赖项存在一些不匹配。