open-api icon indicating copy to clipboard operation
open-api copied to clipboard

Load `.ts` route file

Open agnoam opened this issue 3 years ago • 8 comments

I'm trying to use the express-openapi package I tried to use this configurations in my typescript-node project:

await initialize({
    app, // express app
    exposeApiDocs: true,
    docsPath: '/docs',
    apiDoc: docPath,
    paths: path.resolve(__dirname), // `src/config/`
    routesGlob: '**/*.{ts,js}',
    routesIndexFileRegExp: /(?:index)?\.[tj]s$/
})

But when I tried to run this, it throws me that error: TypeError: Unknown file extension ".ts" for src/config/routes.config.ts

I'm trying to run it in my ts-node development environment. and can not "compile" the code into .js files. Does anyone have idea how to solve this problem?

agnoam avatar Nov 12 '22 20:11 agnoam

I'm running into the same issue and trying to figure it out... Everything works fine with .js or .cjs extension

baophamtd avatar Nov 21 '22 06:11 baophamtd

node --loader ts-node/esm src/main.ts

Used this start cmd. That worked for me.

dominicrico avatar Nov 22 '22 17:11 dominicrico

I'm getting the same issue when running the api through nodemon, which now defaults to using node-ts too

simonv3 avatar Jan 07 '23 02:01 simonv3

nodemon --watch src --ext ts --exec 'node --inspect --loader ts-node/esm src/main.ts'

This one works for us since month with nodemon.

dominicrico avatar Feb 25 '23 20:02 dominicrico

Just bumped from 7.0.1 to 12.1.0 and now getting this as well. ts-node did not solve the issue.

bruce-bjorklund-sophos avatar Apr 25 '23 15:04 bruce-bjorklund-sophos

I have this issue with vitest. With ts-node I was able to fix it with this configuration in the tsconfig.ts: "ts-node": { "esm": true, },

But for vitest I did not find any work around. Anyone achieved to do tests with it?

cbarceloc avatar Sep 06 '23 13:09 cbarceloc

How to pass dependencies in the routes ? I get this error : - throw new Error(${token.value} was not defined in dependencies);

SiddhantBohra avatar Sep 14 '24 16:09 SiddhantBohra

this is still an issue, especially if you are using a framework which controls the TS compilation and package/deployment operations, and/or using dynamic library loading in TS such as https://github.com/backstage/backstage .

Please investigate and provide a resolve -- it makes this engine very hard to use in large, TS-oriented modern applications and platforms, and thus hard to adopt good practices such as OpenAPI self-documentation

amp5208 avatar Dec 05 '24 19:12 amp5208