fern-api / fern

Input OpenAPI. Output SDKs and Docs.
https://buildwithfern.com
Apache License 2.0
2.68k stars 151 forks source link

[Bug] Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme) - runtime: `browser` nextjs react react-query #4767

Open tresorama opened 1 month ago

tresorama commented 1 month ago

Describe the Bug

Trying to use the generated SDK for Typescript inside a React app with Next.js in browser runtime (use client) trigger this error

Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).

All working in a Server Component that use Node runtime. Tested only in local dev.

Information to Reproduce

CLI Version

{
    "organization": "xxxxx",
    "version": "0.43.5"
}

Generator Version

default-group: local
groups:
  local:
    generators:
      - name: fernapi/fern-typescript-node-sdk
        version: 0.39.3
        output:
          location: local-file-system
          path: ../sdks/typescript
api:
  path: openapi/openapi.yml

API Definition

Irrelevant.

Actual SDK

Don't know what to write here

Expected SDK

Don't know what to write here

tresorama commented 1 month ago

I presume this is expected behavior, meaning that the SDK is not supposed to work on browser runtime. It's my first time using fern.

In case is not supported, is planned for the future ?

dsinghvi commented 1 month ago

@tresorama can you:

  1. disable these in your package.json
  2. turn on the config flag for outputEsm and see if that works
tresorama commented 1 month ago

disable these in your package.json

In package.json of sdk consumer app (next.js) or in the project that generate the sdk ?

  1. turn on the config flag for outputEsm and see if that works

Where do I add this ?


My current setup

.
├── backend (fastify + fastify-swagger)
│   ├── package.json
│   ├── src
│   │   ├── plugins
│   │   │   └── fastify-swagger
│   │   └── server.ts
│   └── tsconfig.json
├── frontend (next js)
│   ├── next.config.mjs
│   ├── package.json
│   ├── src
│   │   ├── app
│   │   │   ├── dashboard
│   │   │   ├── globals.css
│   │   │   ├── layout.tsx
│   │   ├── auth
│   │   │   └── auth.login.tsx
│   │   └── lib
│   │       ├── fetcher
│   │       ├── react-query.tsx
│   │       └── utils.ts
│   ├── tailwind.config.ts
│   └── tsconfig.json
└── openapi (fern cli )
    ├── fern
    │   ├── fern.config.json
    │   ├── generators.yml
    │   └── openapi
    │       └── openapi.yml
    ├── package.json
    └── sdks
        └── typescript
            ├── Client.d.ts
            ├── Client.js
            ├── api
            ├── core
            ├── environments.d.ts
            ├── environments.js
            ├── errors
            ├── index.d.ts
            ├── index.js
            └── serialization