[x] used the search to make sure that a similar issue hasn't already been submit
Expected Behavior
In an ESM project with "type": "module" using tsoa, the CLI should be able to import tsoa-config.js or tsoa-config.cjs.
Current Behavior
I'm converting a project using tsoa from CJS to ESM. The project has its tsoa config not as JSON, but in tsoa-config.js. After moving to ESM and adding "type": "module" in package.json, the tsoa CLI breaks because it tries torequire the config.
The CLI itself is a CJS package, but tsoa-config.js is now considered ESM by node because of type: module. Here's the actual code that fails and here's the same from the CLI's bundle:
A solution is renaming tsoa-config.js to tsoa-config.cjs to force CJS and make the CLI's require work. However, as we can also see in the snippet above, the CLI doesn't recognise the .cjs extension as JS. Instead, it falls back to parsing the file as JSON, resulting in another error.
Possible Solution
The CLI could simply accept .js and .cjs extensions for JS config files.
I'd be glad to contribute a MR to solve this!
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
In an ESM project with
"type": "module"
using tsoa, the CLI should be able to importtsoa-config.js
ortsoa-config.cjs
.Current Behavior
I'm converting a project using tsoa from CJS to ESM. The project has its tsoa config not as JSON, but in
tsoa-config.js
. After moving to ESM and adding"type": "module"
inpackage.json
, the tsoa CLI breaks because it tries torequire
the config. The CLI itself is a CJS package, buttsoa-config.js
is now considered ESM by node because oftype: module
. Here's the actual code that fails and here's the same from the CLI's bundle:A solution is renaming
tsoa-config.js
totsoa-config.cjs
to force CJS and make the CLI'srequire
work. However, as we can also see in the snippet above, the CLI doesn't recognise the.cjs
extension as JS. Instead, it falls back to parsing the file as JSON, resulting in another error.Possible Solution
The CLI could simply accept
.js
and.cjs
extensions for JS config files. I'd be glad to contribute a MR to solve this!Steps to Reproduce
Here's a small repo with instructions to reproduce the issue. https://github.com/rdsfj/tsoa-cli-repro
Context (Environment)
Version of the library: 6.2.1 Version of NodeJS: tested with 20.7.0 and 22.1.0
Detailed Description
Breaking change?
no