swagger-jsdoc icon indicating copy to clipboard operation
swagger-jsdoc copied to clipboard

"SyntaxError: Unexpected token {" in Typescript Express

Open utmishra opened this issue 3 years ago • 2 comments

Describe the bug

import swaggerJsDoc from 'swagger-jsdoc';
const options = {
  "definition": {
    "openapi": "3.0.0",
    "info": {
      "title": "Hello World",
      "version": "1.0.0"
    }
  },
  "apis": ['./src/routes*.js'],
};

const openapiSpecification = swaggerJsDoc(options);

Setting the above simple default specification on Typescript based Express throws the following error:

import { prepare, extract, organize, finalize } from './src/specification.js';
       ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/utmishra/dev/projects/stories/authentication/src/app.ts:22:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (/Users/utmishra/dev/projects/stories/authentication/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/utmishra/dev/projects/stories/authentication/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/utmishra/dev/projects/stories/authentication/src/index.ts:2:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (/Users/utmishra/dev/projects/stories/authentication/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/utmishra/dev/projects/stories/authentication/node_modules/ts-node/src/index.ts:1059:12)

To Reproduce Steps to reproduce the behaviour:

  1. Run a Typescript Node package with swagger-jsdoc installed

Package version: ^7.0.0-rc.6

Expected behaviour The app runs without throwing an error

Additional context Current workaround:

utmishra avatar May 17 '21 12:05 utmishra

Had same issue, downgrading 6.0.1 fixed it

masives avatar May 20 '21 09:05 masives

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 19 '21 10:07 stale[bot]