8000 Since `v6.5.0` passing compilerOptions to tsoa.json will throw an exception in ts.createProgram · Issue #1727 · lukeautry/tsoa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

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†8000 ™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 of 4 tasks
alanszp opened this issue Dec 8, 2024 · 6 comments
Open
2 of 4 tasks
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted

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.

@WoH WoH added help wanted good first issue This issue could be an easy PR for those looking to help contribute labels Jan 27, 2025
@cwilso03
Copy link
cwilso03 commented Feb 6, 2025

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.

@dimiliev
Copy link

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.

@lobabob
Copy link
lobabob commented May 3, 2025

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/*"]
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted
Projects
None yet
Development

No branches or pull requests

5 participants
0