Load `.ts` route file
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?
I'm running into the same issue and trying to figure it out...
Everything works fine with .js or .cjs extension
node --loader ts-node/esm src/main.ts
Used this start cmd. That worked for me.
I'm getting the same issue when running the api through nodemon, which now defaults to using node-ts too
nodemon --watch src --ext ts --exec 'node --inspect --loader ts-node/esm src/main.ts'
This one works for us since month with nodemon.
Just bumped from 7.0.1 to 12.1.0 and now getting this as well. ts-node did not solve the issue.
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?
How to pass dependencies in the routes ?
I get this error : -
throw new Error(${token.value} was not defined in dependencies);
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