Codegen - No esbuild-runner or ts-node

See original GitHub issue

I just tried the new 1.0.0-alpha.1 version and noticed that I can’t get the example working.

$ npx @rtk-query/codegen-openapi openapi.dev.config.ts
npx: installed 64 in 7.95s
Encountered a TypeScript configfile, but neither esbuild-runner nor ts-node are installed.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I am wondering if it has to do with the esbuild-runner and ts-node listed as dev dependencies so npx is not installing them when running in production?

The only way I have been able to get it to work so far is to call the cli directly:

node ./node_modules/@rtk-query/codegen-openapi/lib/bin/cli.js openapi.dev.config.ts

config file:

import { ConfigFile, generateEndpoints } from "@rtk-query/codegen-openapi";

const {
  parsed: { OPENAPI_DOCS },
} = require("dotenv").config({ path: "./.env.local" });

const config: ConfigFile = {
  schemaFile: OPENAPI_DOCS,
  apiFile: "./src/app/example-api.empty.ts",
  apiImport: "emptyApi",
  outputFile: "./src/app/example-api.generated.ts",
  exportName: "api",
  hooks: true,
};

export default config;

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
floatrxcommented, Dec 20, 2021

Typescript: openapi-config.ts

import { ConfigFile } from '@rtk-query/codegen-openapi';

const config: ConfigFile = {
  schemaFile: './openapi-spec.json',
  apiFile: './src/store/baseApi.ts',
  apiImport: 'baseApi',
  outputFile: './src/store/coreApi.ts',
  exportName: 'coreApi',
  hooks: true,
};

export default config;
 $ npx @rtk-query/codegen-openapi openapi-config.ts
npx: installed 64 in 13.316s
Encountered a TypeScript configfile, but neither esbuild-runner nor ts-node are installed.

but

{
  "schemaFile": "./openapi-spec.json",
  "apiFile": "./src/store/baseApi.ts",
  "apiImport": "baseApi",
  "outputFile": "./src/store/coreApi.ts",
  "exportName": "coreApi",
  "hooks": true
}
npx @rtk-query/codegen-openapi openapi-config.json
npx: installed 64 in 4.483s
Generating ./src/store/coreApi.ts
Done

upd;

npx @rtk-incubator/rtk-query-codegen-openapi openapi-config.ts

package.json

{
  "devDependencies": {
    "@craco/craco": "^6.4.3",
    "@rtk-incubator/rtk-query-codegen-openapi": "^0.5.1",
    "@rtk-query/codegen-openapi": "^1.0.0-alpha.1",
    "craco-alias": "^3.0.1",
    "craco-antd": "^1.19.0",
    "craco-sass-resources-loader": "^1.1.0",
    "typescript": "^4.5.2"
  }
}

works too

7reactions
jonra1993commented, Apr 11, 2022

We were able to make it run correctly with these steps

  1. Install ts-node yarn add ts-node --dev

  2. Add a new script on package.json

"api-generate": " npx @rtk-query/codegen-openapi openapi-config.ts"

  1. Create emptyApi.ts and openapi-config.ts file as sample documentation recommend https://redux-toolkit.js.org/rtk-query/usage/code-generation#openapi
import type { ConfigFile } from '@rtk-query/codegen-openapi'
const config: ConfigFile = {
  schemaFile: 'https://petstore3.swagger.io/api/v3/openapi.json',
  apiFile: './src/services/empty-api.ts',
  apiImport: 'emptySplitApi',
  outputFiles: {
    './src/services/user.ts': {
      filterEndpoints: [/user/i],
    },
    './src/services/order.ts': {
      filterEndpoints: [/order/i],
    },
    './src/services/pet.ts': {
      filterEndpoints: [/pet/i],
    },
  },
  hooks: true,
}
export default config
  1. Generate code yarn api-generate
Read more comments on GitHub >

github_iconTop Results From Across the Web

esbuild-runner - npm
Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild. Latest version: 2.2.2, last published: 2 months ago.
Read more >
ts-node on steroids - DEV Community ‍ ‍
I just released esbuild-runner. It makes it easy to run arbitrary code or tests without needing to build your whole project.
Read more >
jun89920-rtk-query-codegen-openapi - npm package - Snyk
The npm package jun89920-rtk-query-codegen-openapi was scanned for known vulnerabilities and missing license, and no issues were found. Thus the ...
Read more >
Error: TSError: Unable to compile TypeScript - Stack Overflow
I had met same issue. First I remove ts-node and typescript from package.json . then, npm install ts-node --save-dev npm install typescript ......
Read more >
What does it take to support Node.js ESM? – The Guild
There are workarounds, but nothing actually works in 100% of the possible use-cases (see for example, ts-jest issue), and for that reason, we ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found