tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

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

Open alanszp opened this issue 1 year ago • 6 comments

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 ...

    • [x] bug report
    • [ ] feature request
    • [ ] support request
  • I confirm that I

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

Expected Behavior

Running yarn add @tsoa/[email protected] 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/[email protected] 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

alanszp avatar Dec 08 '24 23:12 alanszp

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.👀

github-actions[bot] avatar Dec 08 '24 23:12 github-actions[bot]

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.

WoH avatar Dec 09 '24 20:12 WoH

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

alanszp avatar Dec 25 '24 21:12 alanszp

I can confirm this also happens with any 6.x version of tsoa. When I originally got the error with v6.6.0 and then stumbled upon this bug report, I tried each preceding version to identify the last working one. They all failed the same way until I installed 5.1.1.

In my case, I'm on Node v22, using TypeScript 5.7.3.

cwilso03 avatar Feb 06 '25 20:02 cwilso03

I can reproduce this as well. Using a similar setup:

  • Node v22.14.0 (lts)
  • Typescript 5.7.3
  • pnpm
  • monorepo with shared tsconfig file ( using extends in tsconfig )

The last known version that works for me is v5.1.1.

dimiliev avatar Mar 10 '25 08:03 dimiliev

Can also reproduce. Running node v22.13.1 and typescript 5.7.3. Specifically the "module" and "target" flags cause the issue for me.

My compiler options:

"compilerOptions": {
    "target": "es2024",
    "module": "nodenext",
    "outDir": "./dist",
    "strict": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "removeComments": true,
    "incremental": true,
    "paths": {
      "app:*": ["./app/*"]
    }
  }

lobabob avatar May 03 '25 04:05 lobabob