kubb-labs / kubb

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

attempting to use an illegal dynamic require of "fs" when called from bun #1354

Open lschierer opened 19 hours ago

lschierer commented 19 hours ago

What version of kubb is running?

2.28.3

What platform is your computer?

MacOS

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

"devDependencies": { "@commitlint/cli": "^19.5.0", "@commitlint/config-conventional": "^19.5.0", "@commitlint/types": "^19.5.0", "@eslint/js": "^9.13.0", "@kubb/cli": "^2.28.3", "@kubb/core": "^2.28.3", "@kubb/parser-ts": "^2.28.3", "@kubb/plugin-oas": "^2.28.3", "@kubb/swagger": "^2.28.3", "@kubb/swagger-ts": "^2.28.3", "@kubb/swagger-zod": "^2.28.3", "@release-it/conventional-changelog": "^8.0.2", "@tailwindcss/typography": "^0.5.15", "@types/bun": "^1.1.11", "@types/eslint__js": "^8.42.3", "@types/node": "^22.7.8", "@types/postcss-import": "^14.0.3", "@typescript-eslint/parser": "^8.11.0", "ajv": "^8.17.1", "autoprefixer": "^10.4.20", "eslint": "^9.13.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "husky": "^9.1.6", "orval": "^7.2.0", "postcss": "^8.4.47", "postcss-import": "^16.1.0", "postcss-load-config": "^6.0.1", "postcss-nested": "^6.2.0", "postcss-plugin": "^1.0.0", "rollup-plugin-postcss-lit": "^2.1.0", "tailwindcss": "^3.4.14", "ts-lit-plugin": "^2.0.2", "typescript": "^5.6.3" }, "dependencies": { "@gracile/gracile": "^0.7.1", "@gracile/svg": "^0.1.0", "@hono/arktype-validator": "^2.0.0", "@hono/node-server": "^1.13.2", "@readme/openapi-parser": "^2.6.0", "@spectrum-css/icon": "^7.1.4", "@spectrum-css/page": "^8.1.3", "@spectrum-css/tokens": "^14.5.0", "@spectrum-css/typography": "^6.1.3", "arktype": "^2.0.0-rc.17", "hono": "^4.6.5", "jiti": "^1.21.6", "lint-staged": "^15.2.10", "lit": "^3.2.1", "postcss-lit": "^1.1.1", "prettier": "^3.3.3", "release-it": "^17.10.0", "tsx": "^4.19.1", "typescript-eslint": "^8.11.0", "vite": "^5.4.9" },

What steps can reproduce the bug?

$ bunx kubb -v
πŸ•”  πŸ” Loading config
 ERROR  Dynamic require of "fs" is not supported                                                                                          3:37:28 PM

  at kubb.config.bundled_n90ogx543t.mjs:11:9
  at node_modules/@redocly/openapi-core/lib/utils.js (kubb.config.bundled_n90ogx543t.mjs:658:15)
  at __require2 (kubb.config.bundled_n90ogx543t.mjs:17:51)
  at node_modules/@redocly/openapi-core/lib/index.js (kubb.config.bundled_n90ogx543t.mjs:22245:19)
  at __require2 (kubb.config.bundled_n90ogx543t.mjs:17:51)
  at kubb.config.bundled_n90ogx543t.mjs:29580:35
  at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
  at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
  at async extractResult (node_modules/bundle-require/dist/index.js:166:15)
  at async run (node_modules/bundle-require/dist/index.js:209:17) 

 ERROR  Dynamic require of "fs" is not supported                                                                                          3:37:28 PM

$ 

The error is specific to something about this config file, I'm still trying to narrow down what,

import { defineConfig } from "@kubb/core";
import { pluginTs } from "@kubb/swagger-ts";
import { pluginOas } from "@kubb/plugin-oas";
import { pluginZod } from "@kubb/swagger-zod";

export default defineConfig({
  root: ".",
  input: {
    path: "./share/evonytkrtips-backend.yaml",
  },
  output: {
    path: "./src/api",
    clean: true,
  },
  plugins: [
    pluginOas({
      contentType: "application/json",
      validate: true,
      output: {
        path: "./src/schemas/json",
      },
    }),
    pluginTs({}),
    pluginZod({
      output: {
        path: "./src/schemas",
        exportAs: "evony",
      },
      typed: true,
      typedSchema: true,
    }),
  ],
});

without a config file, it does not complain about the "fs" module, it complains about the lack of config file. a config file based on the above, but with all plugins deleted, runs, but generates no files.

import { defineConfig } from "@kubb/core";
import { pluginOas } from "@kubb/plugin-oas";

export default defineConfig({
  root: ".",
  input: {
    path: "./share/evonytkrtips-backend.yaml",
  },
  output: {
    path: "./src/api",
    clean: true,
  },
  plugins: [
    pluginOas({
      output: {
        path: "schemas",
      },
      validate: true,
    }),
  ],
});

heavily based on the website example, still produces the error. It seems to happen with any one or more plugins listed, with our without configuration.

How often does this bug happen?

Every time

What is the expected behavior?

It should run the same as it does when called from pnpm or npm

Swagger/OpenAPI file?


openapi: 3.1.0 info: title: Evony TKR API version: 0.0.0 description: Allow users to obtain information on Generals, General Pairs, General Conflicts, General SkillBooks, General Specialities, and related information for Evony TKR paths: /generals: get: tags:

Additional information

actually I'm not sure how bun related this is?

$ npx kubb --config kubb.config.ts 
πŸ•‘  πŸ” Loading config
 ERROR  Dynamic require of "fs" is not supported                                                                                          3:48:24 PM

  at kubb.config.bundled_umdq3kn3w6q.mjs:11:9
  at node_modules/@redocly/openapi-core/lib/utils.js (kubb.config.bundled_umdq3kn3w6q.mjs:143:15)
  at __require2 (kubb.config.bundled_umdq3kn3w6q.mjs:14:51)
  at node_modules/@redocly/openapi-core/lib/index.js (kubb.config.bundled_umdq3kn3w6q.mjs:21730:19)
  at __require2 (kubb.config.bundled_umdq3kn3w6q.mjs:14:51)
  at kubb.config.bundled_umdq3kn3w6q.mjs:27732:35
  at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
  at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
  at async extractResult (node_modules/bundle-require/dist/index.js:166:15)
  at async run (node_modules/bundle-require/dist/index.js:209:17) 

 ERROR  Dynamic require of "fs" is not supported                                                                                          3:48:24 PM

$ npx --version
10.7.0
$ node --version
v20.15.0
$ 
linear[bot] commented 19 hours ago

KUBB-54 attempting to use an illegal dynamic require of "fs" when called from bun