我正在尝试通过 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
我有几个问题:
这是完整的日志:
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.config.js
文件中解决了我的问题
webpack: config => {
config.ignoreWarnings = [
{module: /node_modules\/swagger-jsdoc\/src\/utils\.js/},
{file: /node_modules\/swagger-jsdoc\/src\/index\.js/},
];
return config;
},