redux-toolkit
redux-toolkit copied to clipboard
`"moduleResolution": "bundler"` in `tsconfig.json` breaks codegen command
I encounter this error when I try to run the OpenAPI codegen command:
❯ npx @rtk-query/codegen-openapi src/common/openapi/api-generator-config.cts
/home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
at createTSError (/home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:863:19)
at /home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:1379:34
at Object.compile (/home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:1455:13)
at Module.m._compile (/home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Object.require.extensions.<computed> [as .js] (/home/giammyisjammy/Projects/expwebclient/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
at Module.require (node:internal/modules/cjs/loader:1233:19) {
diagnosticCodes: [ 5095 ]
}
Apparently this is caused by a flag that I changed in my tsconfig.json from:
{
// ...
"moduleResolution": "node",
// ...
}
to:
{
// ...
"moduleResolution": "bundler",
// ...
}
This comes from a standard tsconfig.json from a Vite app created by npm create vite@latest expwebclient -- --template react-ts.
Is it possible to pass different flags to the @rtk-query/codegen-openapi command?
Either via command line flag (i.e.: @rtk-query/codegen-openapi path/to/config/file.cts --moduleResolution node) or passing a different tsconfig.json file (i.e.: @rtk-query/codegen-openapi path/to/config/file.cts --project path/to/tsconfig.codegen-openapi.json).
For context, here's my complete tsconfig.json file:
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"types": ["vite/client", "vite-plugin-svgr/client", "vitest/globals"],
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}