samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.79k stars 93 forks source link

npx nestia sdk -> error TS5024: Compiler option 'jsx' requires a value of type string. #966

Closed Jamie-Fairweather closed 1 month ago

Jamie-Fairweather commented 1 month ago

When running the npx nestia sdk command, I receive the following error: error TS5024: Compiler option 'jsx' requires a value of type string.

i have a workaround by removing "jsx": "preserve", from my tsconfig.json, running the command, then adding the line back. Tho this isnt ideal.

I'm not sure if this is a Nestia related issue or if its typescript itself

Step by step

  1. jsx option is present image
  2. command fails image
  3. remove jsx option image
  4. command all good image
  5. add jsx option back to tsconfig
p-sw commented 1 month ago

I got same error, and I fixed this with yarn patch.

Reason

  1. nestia sdk internally uses NestiaConfigLoader
  2. NestiaConfigLoader's which uses tsconfck.parseNative to parse compilerOption from tsconfig (reference here)
  3. tsconfck.parseNative uses typescript's native function, readConfigFile and parseJsonConfigFileContent
  4. parseJsonConfigFileContent causes error - it resolves jsx to number, but jsx should be string!
  5. ERROR

Temporary workarounds

Use yarn patch or patch-package to modify the NestiaConfigLoader to use tsconfck.parse instead of tsconfck.parseNative

Here is my patch file:

diff --git a/lib/executable/internal/NestiaConfigLoader.js b/lib/executable/internal/NestiaConfigLoader.js
index 5a47d1e5c00a5fcd0f2156be49b60eec90260ae1..86fc1003983635dd2396e3b5f3207594446b5509 100644
--- a/lib/executable/internal/NestiaConfigLoader.js
+++ b/lib/executable/internal/NestiaConfigLoader.js
@@ -59,7 +59,7 @@ var NestiaConfigLoader;
         const configFileName = typescript_1.default.findConfigFile(process.cwd(), typescript_1.default.sys.fileExists, project);
         if (!configFileName)
             throw new Error(`unable to find "${project}" file.`);
-        const { tsconfig } = yield (0, tsconfck_1.parseNative)(configFileName);
+        const { tsconfig } = yield (0, tsconfck_1.parse)(configFileName);
         const configFileText = JSON.stringify(tsconfig);
         const { config } = typescript_1.default.parseConfigFileTextToJson(configFileName, configFileText);
         const configParseResult = typescript_1.default.parseJsonConfigFileContent(config, typescript_1.default.sys, path_1.default.dirname(configFileName));
diff --git a/src/executable/internal/NestiaConfigLoader.ts b/src/executable/internal/NestiaConfigLoader.ts
index 29112b0a27454886afaa824f1aa670cad3301536..ecc7a73c3eeea9585cb2ed035de4dd203b15fa15 100644
--- a/src/executable/internal/NestiaConfigLoader.ts
+++ b/src/executable/internal/NestiaConfigLoader.ts
@@ -1,7 +1,7 @@
 import fs from "fs";
 import path from "path";
 import { register } from "ts-node";
-import { parseNative } from "tsconfck";
+import { parse } from "tsconfck";
 import ts from "typescript";
 import typia from "typia";

@@ -18,7 +18,7 @@ export namespace NestiaConfigLoader {
     );
     if (!configFileName) throw new Error(`unable to find "${project}" file.`);

-    const { tsconfig } = await parseNative(configFileName);
+    const { tsconfig } = await parse(configFileName);
     const configFileText = JSON.stringify(tsconfig);
     const { config } = ts.parseConfigFileTextToJson(
       configFileName,

apply, and it works fine without error.

I tested only what I use right now:

  1. sdk, swagger build
  2. dev
  3. build

But I believe there will be no error on production too.

I checked out log and commit 6b7cf1e added parseNative. @samchon is there any specific reason to use parseNative instead of parse?

+ I tested out with two different version: nestia's dependency version (^2.0.1) and latest version (3.1.1).
latest version causes same problem, too.