Closed jomadel closed 1 week ago
Also cmp. https://github.com/reduxjs/redux-toolkit/issues/1795 by the way.
Best regards, jomadel
I was just trying to give RTK a try/ evaluation for use, this was pretty much the first thing I ran into. Has put a lot of doubts in my mind, is this package still considered relevant and being actively maintained for example. That is a pretty old version of Prettier there.
It's on our list to address, but we shipped RTK 2.0 right before the holidays, and none of us have had free time to do any real RTK work in the last month due to holidays and family time.
(Note that RTK itself is fine - this is just about the RTKQ codegen.)
In the past, this was only a problem when formatting .js
files, which the codegen cannot generate anyways, since it always generates .ts
files.
If that has changed with prettier 3, would you be willing to submit a PR to update prettier and change these settings?
Should be live in https://github.com/reduxjs/redux-toolkit/releases/tag/%40rtk-query%2Fcodegen-openapi%402.0.0-alpha.0 ! Please try it out and let us know if it works.
When I execute the basic example for code generation from https://redux-toolkit.js.org/rtk-query/usage/code-generation for a javascript-environment, I get:
npx @rtk-query/codegen-openapi openapi-config.js Generating petApi.js ConfigError: Couldn't resolve parser "babylon" at requireParser (C:\temp\openapi-test\openapi-test\node_modules\prettier\index.js:6616:15) at resolveParser (C:\temp\openapi-test\openapi-test\node_modules\prettier\index.js:7497:16) at normalize (C:\temp\openapi-test\openapi-test\node_modules\prettier\index.js:7741:22) at formatWithCursor2 (C:\temp\openapi-test\openapi-test\node_modules\prettier\index.js:9006:50) at C:\temp\openapi-test\openapi-test\node_modules\prettier\index.js:38168:12 at Object.format (C:\temp\openapi-test\openapi-test\node_modules\prettier\index.js:38182:12) at prettify (C:\temp\openapi-test\openapi-test\node_modules\@rtk-query\codegen-openapi\lib\utils\prettier.js:53:21) at async generateEndpoints (C:\temp\openapi-test\openapi-test\node_modules\@rtk-query\codegen-openapi\lib\index.js:21:87) at async run (C:\temp\openapi-test\openapi-test\node_modules\@rtk-query\codegen-openapi\lib\bin\cli.js:59:13)
The issue seems to be that in @rtk-query\codegen-openapi\lib\utils\prettier.ts there is a config array which defines the parser for each file type like so:
const EXTENSION_TO_PARSER = { ts: 'typescript', tsx: 'typescript', js: 'babylon', jsx: 'babylon', 'js.flow': 'flow', flow: 'flow', gql: 'graphql', graphql: 'graphql', css: 'postcss', scss: 'postcss', less: 'postcss', stylus: 'postcss', markdown: 'markdown', md: 'markdown', json: 'json', };
It seems that babylon is no longer the valid parser for js or jsx-files. Instead babel should be used.