-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cannot run codegen CLI command on .cts or .cjs files (CommonJS) #2437
Comments
Hit this issue too. Trying to make private NPM packages of our generated files to save having multiple copies all over the place. |
@Macludde I've updated to that package but still hit the issue:
|
Your config file needs to be a .cts files and not .ts (and .cjs instead of .js). The change introduced by the PR above simply expanded the regex check to allow for .cts and .cjs files for the config. In a regular project all .ts and .js files are automatically marked as CommonJS but when |
I have a project which uses Vite and thus also uses
type:"module"
in its package.json.Error description
When running
npx @rtk-query/codegen-openapi
I get the following error:Reason for error
The above error is caused by the config file being inside the package.json project whilst also having
type: "module"
specified. One fix to get around this is declaring generationConfig.ts as generationConfig.cts instead to tell it to use CommonJS imports instead of ESM.However, this doesn't work with
@rtk-query/codegen-openapi
as in the cli file, on line 46, the regex for checking if the path given is to a correct file is as follows/\.(jsx?|tsx?|jsonc?)?$/
This doesn't match to files ending in .cjs or .cts
Possible solution
An easy fix would be to change the regex to
/\.(c?(jsx?|tsx?)|jsonc?)?$/
The text was updated successfully, but these errors were encountered: