[英]Syntax Error: swagger-jsdoc setup in Nodejs Typescript Express
I am getting a syntax error on trying to set up swagger with typescript express app.我在尝试使用 typescript express 应用程序设置 swagger 时遇到语法错误。 When I tried this without the swagger-jsdoc ie using swagger.json it was working but when I am trying to use swagger-jsdoc for documenting I am facing the following error So please can any body help me in resolving this issue.当我在没有 swagger-jsdoc 的情况下尝试此操作时,即使用 swagger.json 它正在工作,但是当我尝试使用 swagger-jsdoc 进行记录时,我遇到了以下错误所以请任何人帮助我解决这个问题。
This is my app.ts这是我的 app.ts
import bodyParser from "body-parser";
import express, { RequestHandler } from "express";
import morgan from "morgan";
import v1 from "./routes/v1";
import swaggerUi from "swagger-ui-express";
import swaggerJsdoc from "swagger-jsdoc";
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const swaggerDefinition = {
openapi: "3.0.0",
info: {
title: "Homework APP",
version: "0.1.0",
description: "This is a simple CRUD API application made with Express and documented with Swagger",
},
servers: [
{
"url": "/",
"description": "Local Dev"
},
],
}
const options = {
swaggerDefinition,
apis: ["./src/routes/v1/*.ts"],
}
const specs = swaggerJsdoc(options);
app.use(morgan(":status :method :url :response-time ms"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs))
app.use(v1);
export default app;
ERROR错误
(function (exports, require, module, __filename, __dirname) { import { prepare, extract, organize, finalize } from './src/specification.js';
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/aman/Documents/Octo/homeworkapp-server/src/app.ts:6:1)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Module.m._compile (/home/aman/Documents/Octo/homeworkapp-server/node_modules/ts-node/src/index.ts:1056:23)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.require.extensions.(anonymous function) [as .ts] (/home/aman/Documents/Octo/homeworkapp-server/node_modules/ts-node/src/index.ts:1059:12)
at Module.load (internal/modules/cjs/loader.js:598:32)
[nodemon] app crashed - waiting for file changes before starting...
I was able to resolve this issue by rolling back the swagger-jsdoc version to "swagger-jsdoc": "^6.0.0"
我能够通过将 swagger-jsdoc 版本回滚到"swagger-jsdoc": "^6.0.0"
来解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.