reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.64k stars 1.15k forks source link

babylon is outdated as a js parser #3155

Closed jomadel closed 1 week ago

jomadel commented 1 year ago

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.

jomadel commented 1 year ago

Also cmp. https://github.com/reduxjs/redux-toolkit/issues/1795 by the way.

Best regards, jomadel

johnmorton503 commented 8 months ago

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.

markerikson commented 8 months ago

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.)

phryneas commented 8 months ago

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?

markerikson commented 1 week ago

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.