预渲染页面“/api-doc”时发生错误 - Next 13 (npm)

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

我正在尝试通过 next-swagger-doc 添加 Swagger 文档。端点文档在本地渲染和工作正常,但无法在 Docker 容器内或 Vercel 部署中构建。该代码是文档中“使用案例 1”的精确复制品:https://github.com/jellydn/next-swagger-doc

渲染 Swagger 文档页面(按预期工作)时,我遇到了以下警告:

- warn ./node_modules/swagger-jsdoc/src/utils.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/swagger-jsdoc/src/utils.js
./node_modules/swagger-jsdoc/src/specification.js
./node_modules/swagger-jsdoc/src/lib.js
./node_modules/swagger-jsdoc/index.js
./node_modules/next-swagger-doc/dist/index.js
./swagger.ts
./app/api-doc/page.tsx

我有几个问题:

  1. Node 和 Yarn 之间的选择重要吗?我们正在使用节点 16。
  2. 如何解决此类型错误?

这是完整的日志:

41.42 TypeError: Class extends value undefined is not a constructor or null
41.42     at /app/.next/server/chunks/334.js:28855:816054
41.42     at /app/.next/server/chunks/334.js:28855:1386511
41.42     at /app/.next/server/chunks/334.js:28855:1386527
41.42     at webpackUniversalModuleDefinition (/app/.next/server/chunks/334.js:28855:70)
41.42     at Object.20404 (/app/.next/server/chunks/334.js:28855:76)
41.42     at __webpack_require__ (/app/.next/server/webpack-runtime.js:25:43)
41.42     at Object.93670 (/app/.next/server/chunks/334.js:34301:69)
41.42     at __webpack_require__ (/app/.next/server/webpack-runtime.js:25:43)
41.42     at Module.6054 (/app/.next/server/app/api-doc/page.js:336:74)
41.42     at __webpack_require__ (/app/.next/server/webpack-runtime.js:25:43)
41.42 
41.42 Error occurred prerendering page "/api-doc". Read more: https://nextjs.org/docs/messages/prerender-error
41.42 TypeError: Class extends value undefined is not a constructor or null
41.42     at /app/.next/server/chunks/334.js:28855:816054
41.42     at /app/.next/server/chunks/334.js:28855:1386511
41.42     at /app/.next/server/chunks/334.js:28855:1386527
41.42     at webpackUniversalModuleDefinition (/app/.next/server/chunks/334.js:28855:70)
41.42     at Object.20404 (/app/.next/server/chunks/334.js:28855:76)
41.42     at __webpack_require__ (/app/.next/server/webpack-runtime.js:25:43)
41.42     at Object.93670 (/app/.next/server/chunks/334.js:34301:69)
41.42     at __webpack_require__ (/app/.next/server/webpack-runtime.js:25:43)
41.42     at Module.6054 (/app/.next/server/app/api-doc/page.js:336:74)
41.42     at __webpack_require__ (/app/.next/server/webpack-runtime.js:25:43)
41.42 - info Generating static pages (24/33)
next.js swagger-ui next.js13
1个回答
0
投票

将下面的代码添加到我的

next.config.js
文件中解决了我的问题

  webpack: config => {
    config.ignoreWarnings = [
      {module: /node_modules\/swagger-jsdoc\/src\/utils\.js/},
      {file: /node_modules\/swagger-jsdoc\/src\/index\.js/},
    ];

    return config;
  },
© www.soinside.com 2019 - 2024. All rights reserved.