swagger 为什么会出现这个错误消息:未能找到模块“jsdoc”的声明文件

2izufjch  于 2023-10-18  发布在  其他
关注(0)|答案(2)|浏览(169)

这是我的安装结果:

success Saved 19 new dependencies.
info Direct dependencies
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
info All dependencies
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]

success Saved 13 new dependencies.
info Direct dependencies
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ [email protected]
└─ [email protected]
info All dependencies
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ [email protected]
└─ [email protected]

但我仍然收到这些错误消息:

Could not find a declaration file for module 'swagger-jsdoc'. 'C:/Users/A/Desktop/desktop/base_code/back_bc_node/node_modules/swagger-jsdoc/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/swagger-jsdoc` if it exists or add a new declaration (.d.ts) file containing `declare module 'swagger-jsdoc';`

Could not find a declaration file for module 'swagger-ui-express'. 'C:/Users/A/Desktop/desktop/base_code/back_bc_node/node_modules/swagger-ui-express/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/swagger-ui-express` if it exists or add a new declaration (.d.ts) file containing `declare module 'swagger-ui-express';`

这就是我如何导入它:

import swaggerJsdoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";

我不知道为什么我得到这个错误消息,因为它是工作在我以前的应用程序,但不工作在新的应用程序。我试图重新安装swagger,但没有工作。

2w3kk1z5

2w3kk1z51#

我试着按照错误消息中建议的命令操作,结果成功了:

npm i --save-dev @types/swagger-jsdoc
npm i --save-dev @types/swagger-ui-express

但它也在我的项目中创建了一个名为package-lock.json的新文件,我不知道这是不是一件好事,因为我正在使用yarn,这是我尝试的第一个npm命令。我也不知道这个新添加的文件package-lock.json是否对我的项目是必要的?

yftpprvb

yftpprvb2#

请尝试

yarn add @types/swagger-jsdoc swagger-jsdoc @types/swagger-ui-express swagger-ui-express

然后在app.ts文件中

import swaggerJSDocs  from "swagger-jsdoc";
import swaggerUi  from "swagger-ui-express"

相关问题