Skip to content
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

Codegen: Couldn't resolve parser "babylon" when output file has js/jsx extension #1795

Closed
zoubingwu opened this issue Dec 2, 2021 · 6 comments · Fixed by #4589
Closed

Codegen: Couldn't resolve parser "babylon" when output file has js/jsx extension #1795

zoubingwu opened this issue Dec 2, 2021 · 6 comments · Fixed by #4589

Comments

@zoubingwu
Copy link

zoubingwu commented Dec 2, 2021

Prettier renamed babylon parser to babel in 1.16 and remove the deprecated one in 2.0, guess everyone is using ts as output so no one reported this issue?

Just change the EXTENSION_TO_PARSER will solve the issue, but seems it only generates ts code (with type annotations it still throws error when trying to prettify it with babel parser), not sure why it should have this paser map.

const EXTENSION_TO_PARSER = {
    ts: 'typescript',
    tsx: 'typescript',
-   js: 'babylon',
+   js: 'babel',
-   jsx 'babylon',
+   jsx: 'babel',
    'js.flow': 'flow',
    flow: 'flow',
    gql: 'graphql',
    graphql: 'graphql',
    css: 'postcss',
    scss: 'postcss',
    less: 'postcss',
    stylus: 'postcss',
    markdown: 'markdown',
    md: 'markdown',
    json: 'json',
};
@phryneas
Copy link
Member

phryneas commented Dec 2, 2021

That should be pretty irrelevant - the codegen creates TypeScript, not JavaScript. You should not give the created files the extension js/x as that is just wrong.

@zoubingwu
Copy link
Author

zoubingwu commented Dec 2, 2021

Yeah, I don't even realize that at first, just copied code from doc and trying to run it.

image

@zoubingwu
Copy link
Author

zoubingwu commented Dec 2, 2021

@phryneas Hey I also run into a parsing error when testing this tool on an larger project:

image

This might related to prettier's ts parser not supporting some latest feature. Is it possible to provide an option to skip the prettier process? Since normally we'll have a pre-commit hook to do that job.

@zoubingwu
Copy link
Author

Hmm, found this is dependency issue, I had typescript v4.4.4 installed, downgrade to 4.3 solved it.

@phryneas
Copy link
Member

phryneas commented Dec 2, 2021

I updated the file names in the docs to .ts, thanks for the catch. We might support down-transpilation to .js in the future, but right now it's not supported, so I'm going to close this issue.

As for the dependency issue: if you can create a reproduction for that, I'd like to take a look at it (but I'm swamped right now, so my feedback could take a while) - but please open a separate issue for that :)

@markerikson
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants