Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since v6.5.0 passing compilerOptions to tsoa.json will throw an exception in ts.createProgram #1727

Open
2 of 4 tasks
alanszp opened this issue Dec 8, 2024 · 3 comments
Open
2 of 4 tasks

Comments

@alanszp
Copy link

alanszp commented Dec 8, 2024

Since v6.5.0 passing compilerOptions in tsoa.json is raising an error when using ANY cli fn:

Generate routes error.
 Error: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram
    at createProgram (<redacted>/node_modules/typescript/lib/typescript.js:125523:15)
    at MetadataGenerator.setProgramToDynamicControllersFiles (<redacted>/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:152:47)

I isolate the v6.5.0 since I tried the same code in v6.4.0 and it still works.

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

Running yarn add @tsoa/cli@6.4.0 and then yarn tsoa spec-and-routes produces:

✨  Done in 1.41s.

Node Version 20 and 22 (tried both)

tsoa.json

{
  "entryFile": "src/api/index.ts",
  "noImplicitAdditionalProperties": "silently-remove-extras",
  "controllerPathGlobs": [
    "src/api/endpoints/**/*.ts"
  ],
  "spec": {
    "outputDirectory": "docs",
    "specVersion": 3,
    "version": "1.0.0",
    "name": "Service API",
    "description": "Service"
  },
  "routes": {
    "authenticationModule": "./src/api/middlewares/authWithMethods.ts",
    "routesDir": "src/api/tsoa",
    "middleware": "express"
  },
  "compilerOptions": {
    "lib": [
      "es2023"
    ],
    "module": "node16",
    "target": "es2022",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "paths": {
      "@/*": [
        "src/*"
      ],
      "tsoa": [
        "node_modules/tsoa/dist"
      ],
      "tsoa/": [
        "node_modules/tsoa/dist/"
      ]
    }
  }
}

Current Behavior

Running yarn add @tsoa/cli@6.5.0 and then yarn tsoa spec-and-routes produces:

Generate routes error.
 Error: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram
    at createProgram (<redacted>/node_modules/typescript/lib/typescript.js:125523:15)
    at MetadataGenerator.setProgramToDynamicControllersFiles (<redacted>/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:152:47)

Possible Solution

I tried monkeypatching the code in MetadataGenerator.setProgramToDynamicControllersFiles to parse the this.compilerOptions with parseJsonSourceFileConfigFileContent before sending to createProgram and its working!

Steps to Reproduce

  1. Install v6.5.0 or above of the cli
  2. With node 22 run with the compilerOptions passed above
  3. It will generate this error

Context (Environment)

Version of the library: v6.5.0
Version of NodeJS: 22 or 20

  • Confirm you were using yarn not npm: [x]

Breaking change?

It's only happening since v6.5.0

Copy link

github-actions bot commented Dec 8, 2024

Hello there alanszp 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@alanszp alanszp changed the title Since v6.5.0 passing compilerOptions is using incorrectly ts.createProgram Since v6.5.0 passing compilerOptions to tsoa.json will throw an exception in ts.createProgram Dec 8, 2024
@WoH
Copy link
Collaborator

WoH commented Dec 9, 2024

Any chance you also reverted tsoa's typescript version via lock file when up/downgrading?
I'd suspect TS changed something there, but I'll check their change logs.

@alanszp
Copy link
Author

alanszp commented Dec 25, 2024

@WoH No, I didn't change the typescript version.
Even, when I freshly installed it in a new repo this happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants