kubb-labs / kubb

The ultimate toolkit for working with APIs.
https://kubb.dev
MIT License
643 stars 47 forks source link

Error running `kubb`: ERROR swaggerPlugin.context.getOas is not a function #1139

Open lucivaldo opened 2 weeks ago

lucivaldo commented 2 weeks ago

What version of kubb is running?

2.25.1

What platform is your computer?

Linux

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

{ "name": "my-project-next", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@kubb/cli": "^2.25.1", "@kubb/core": "^2.25.1", "@kubb/plugin-oas": "^3.0.0-alpha.4", "@kubb/plugin-tanstack-query": "^3.0.0-alpha.4", "@kubb/plugin-ts": "^3.0.0-alpha.4", "next": "14.2.6", "react": "^18", "react-dom": "^18" }, "devDependencies": { "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8", "eslint-config-next": "14.2.6", "typescript": "^5" } }

What steps can reproduce the bug?

  1. New installation of Next.js
  2. Installing core packages and working with TanStack Query: npm i @kubb/cli @kubb/core @kubb/plugin-oas @kubb/plugin-tanstack-query @kubb/plugin-ts
  3. Creating the kubb configuration file kubb.config.ts at the root of the project with the content:
    
    import { defineConfig } from '@kubb/core'
    import { pluginOas } from '@kubb/plugin-oas'
    import { pluginTanstackQuery } from '@kubb/plugin-tanstack-query'
    import { pluginTs } from '@kubb/plugin-ts'

export default defineConfig({ root: '.', input: { path: './.tmp/myproject-swagger-api.json', }, output: { path: './src/gen', clean: true, }, plugins: [ pluginOas({}), pluginTs({}), pluginTanstackQuery({}), ], })

4. Run the command to generate the code: `kubb --config kubb.config.ts` or `kubb`
```bash
❯ kubb --config kubb.config.ts
✔ 🔍 Config loaded(kubb.config.ts)
✖ 🚀 Build failed ./.tmp/myproject-swagger-api.json
                                                                                                                                                                                               12:02:54 PM

  Plugins:      3 failed, 3 total
   Failed:      plugin-oas, plugin-ts, plugin-tanstack-query
Generated:      252 files
     Time:      0.875s
    Ended:      Sun Aug 25 2024 12:02:54 GMT-0300 (Brasilia Standard Time)
   Output:      .

 ERROR  swaggerPlugin.context.getOas is not a function (plugin: plugin-ts, hook: buildStart) (plugin: plugin-ts, hook: buildStart)                                                             12:02:54 PM

  at EventEmitter.<anonymous> (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/chunk-3OXCZ5DJ.js:145:19)
  at EventEmitter.emit (node:events:519:28)
  at EventEmitter.emit (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/chunk-3OXCZ5DJ.js:101:34)
  at Object.emit (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/chunk-3OXCZ5DJ.js:158:21)
  at PluginManager.catcher_fn (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/index.js:614:15)
  at /home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/index.js:406:69
  at Array.forEach (<anonymous>)
  at PluginManager.hookParallel (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/index.js:403:13)
  at async safeBuild (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/node_modules/@kubb/core/dist/index.js:787:5)
  at async generate (/home/myuser/.asdf/installs/nodejs/20.17.0/lib/node_modules/@kubb/cli/dist/chunk-VGYRBGKV.js:214:36)

How often does this bug happen?

Every time

What is the expected behavior?

Have the code generated

Swagger/OpenAPI file?

No response

Additional information

No response

stijnvanhulle commented 2 weeks ago

The docs on Kubb were redirecting to the alpha version(v3) which makes a part of your deps being redirected to v3 instead of the stable version(v2). Best to update your package.json again with the following(see ^2.25.1):

{ "name": "my-project-next", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@kubb/cli": "^2.25.1", "@kubb/core": "^2.25.1", "@kubb/plugin-oas": "^2.25.1", "@kubb/swagger-tanstack-query": "^2.25.1", "@kubb/swagger-ts": "^2.25.1", "next": "14.2.6", "react": "^18", "react-dom": "^18" }, "devDependencies": { "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8", "eslint-config-next": "14.2.6", "typescript": "^5" } }