Skip to content

Blank import aliases when generating with hooks and a custom baseQuery #83

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

Closed
tricheco opened this issue Nov 17, 2021 · 13 comments
Closed

Comments

@tricheco
Copy link

tricheco commented Nov 17, 2021

When running (roughly) this command in CI today:

npx @rtk-incubator/rtk-query-codegen-openapi --hooks --baseQuery infr/baseQuery.ts openapi.yml > dest.ts

I got this error.

SyntaxError: Identifier expected. (1:24)
> 1 | import { createApi as  } from "@reduxjs/toolkit/query/react";
    |                        ^
  2 | import { type customBaseQuery as  } from "infr/baseQuery";
  3 | export const api = createApi({
  4 |     baseQuery: customBaseQuery,
    at e (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/parser-typescript.js:1:322)
    at /home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/parser-typescript.js:22:3328487
    at Object.parse (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/parser-typescript.js:22:3328520)
    at Object.parse$a [as parse] (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/index.js:12513:19)
    at coreFormat (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/index.js:14044:16)
    at formatWithCursor$1 (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/index.js:14284:14)
    at /home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/index.js:59304:12
    at Object.format (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/prettier/index.js:59324:12)
    at prettify (/home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/@rtk-incubator/rtk-query-codegen-openapi/lib/utils/prettier.js:53:21)
    at /home/runner/.npm/_npx/3c5ed9efbe5d2091/node_modules/@rtk-incubator/rtk-query-codegen-openapi/lib/bin/cli.js:92:52 {
  loc: { start: { line: 1, column: 24 } },
  codeFrame: '> 1 | import { createApi as  } from "@reduxjs/toolkit/query/react";\n' +
    '    |                        ^\n' +
    '  2 | import { type customBaseQuery as  } from "infr/baseQuery";\n' +
    '  3 | export const api = createApi({\n' +
    '  4 |     baseQuery: customBaseQuery,'
}

I have the same version in local, and that was working until I cleared my npx cache, after which the problem appeared there too.

PS: the problem started occurring today (using 0.5.0), and after a few successful runs in the last few days, without changing the definition.

@Meligy
Copy link

Meligy commented Nov 18, 2021

This seems to happening when using TypeScript 4.5.

@Meligy
Copy link

Meligy commented Nov 18, 2021

Probably caused by dsherret/ts-morph#1221.

@pdll
Copy link

pdll commented Nov 18, 2021

Having the same issue. It's quite critical for out project, because we are relying on RTK query codegen.

@phryneas
Copy link
Collaborator

Then please for now use the codegen from a second folder with TS 4.4 installed. I just had an eye operation and can't even see on both eyes yet, it's highly unlikely I'll be able to fix this on short terms notice.

@pdll
Copy link

pdll commented Nov 18, 2021

Didn't work for me. Tried using TS 4.4.4 and 4.1.6

@phryneas
Copy link
Collaborator

Well, some dependency suddenly changed. Our package didn't - and I'm sorry, right now I just cannot debug this.
You'll have to try around with different dependencies.

@pdll
Copy link

pdll commented Nov 18, 2021

Maybe someone from your team can debug this?

@ericlamb
Copy link

ericlamb commented Nov 18, 2021

I was able to work around this by installing the @rtk-incubator/rtk-query-codegen-openapi package in my React project as a dev dependency. Then changing the paths in the build process to execute the command from the React project folder. My React projects is using TypeScript version ^4.4.4.

npm install --save-dev @rtk-incubator/rtk-query-codegen-openapi

Previously I was running the npx command from the folder with my backend code. This was causing it to use a globally installed version of TypeScript which must have automatically updated yesterday when TS 4.5 was released.

@phryneas
Copy link
Collaborator

Could you please give me feedback if #84 works for you as a fix?

@Meligy
Copy link

Meligy commented Nov 18, 2021

@phryneas is there a way to try it as an npm package without linking etc.? Thanks.

@phryneas
Copy link
Collaborator

phryneas commented Nov 19, 2021

Unfortunately not - after moving to the RTK monorepo we'll have CodeSandbox package builds for each commit. Right now I'd recommend building locally and installing this with yalc.

@Meligy
Copy link

Meligy commented Nov 19, 2021

I found another small issue, and added testing commands to the PR.

@phryneas
Copy link
Collaborator

phryneas commented Nov 21, 2021

fixed in https://github.com/rtk-incubator/rtk-query-codegen/releases/tag/v0.5.1

Please note that we will soon release @rtk-query/codegen-openapi so make sure to keep an eye on reduxjs/redux-toolkit#1680.

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

No branches or pull requests

5 participants