vega / ts-json-schema-generator

Generate JSON schema from your Typescript sources
MIT License
1.43k stars 191 forks source link

Crash when esModuleInterop is disabled in tsconfig.json #640

Open Ririshi opened 3 years ago

Ririshi commented 3 years ago

Calling ts-json-schema-generator while esModuleInterop is disabled in the provided tsconfig.json causes an error:

Module '.../.yarn/cache/typescript-patch-7a9e6321b3-017af99214.zip/node_modules/typescript/lib/typescript"' can only be default-imported using the 'esModuleInterop' flag

I initially thought it was happening because I am using Yarn 2, but I am not sure if that is indeed the cause.

domoritz commented 3 years ago

Hmm, is that a problem in my library or with typescript-patch or typescript?

Ririshi commented 3 years ago

Ah, fair enough. I forgot to add the first part of the error message:

.../.yarn/cache/ts-json-schema-generator-npm-0.83.2-d9cde4e2b0-96c34d8aef.zip/node_modules/ts-json-schema-generator/dist/factory/parser.d.ts(1,8): <original part of the error in OP>

It does seem to be happening inside a ts-json-schema-generator file.

domoritz commented 3 years ago

You should not need the d.ts file. Instead, just use the javascript cli bundle. If you want to use the library, enable esModuleInterop.

Ririshi commented 3 years ago

This is the error I get when running ts-json-schema-generator -f tsconfig.json -t ConfigJson -o configSchema.json...

domoritz commented 3 years ago

And with esModuleInterop it works?

Ririshi commented 3 years ago

It works yes. I do get a different error specific to my configuration, but that's not in the scope of this ticket.

domoritz commented 3 years ago

Then I expect esModuleInterop to be set. If that doesn't work for you, please send a pull request.

kmturley commented 7 months ago

I was receiving the same error when running: ts-json-schema-generator --path 'my/project/**/*.ts' --type 'My.Type.Name'

The script does not pick up tsconfig.json by default.

Adjusting the command to pass in the config fixed the issue: ts-json-schema-generator -f tsconfig.json --path 'my/project/**/*.ts' --type 'My.Type.Name'