question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated Client uses NodeJS exclusive Buffer API

See original GitHub issue

Describe the bug I create the client with the intent of using it in the Browser with the following options:

"scripts": {
    "api:generate-client": "openapi --client axios --input ./src/api/openapi.yml --output ./src/api/client --useOptions --useUnionTypes && prettier --write src/api/client"
}

This generates a client that uses a NodeJS exclusive Buffer API in the file core/request.ts, which leads to a TS Error:

TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
function base64(str: string): string {
  try {
    return btoa(str);
  } catch (err) {
    return Buffer.from(str).toString("base64"); // Buffer does not exist in Browser environments
  }
}

Used Versions:

"devDependencies": {
    ...
    "axios": "^0.24.0",
    "cross-blob": "2.0.1",
    "form-data": "4.0.0",
    "openapi-typescript-codegen": "^0.12.5",
    ...
  },

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wjdpcommented, Jan 6, 2022

Fantastic, thanks for the update @ferdikoomen

1reaction
ferdikoomencommented, Jan 6, 2022

@wjdp @manuschillerdev There is a fix for this in the development branch now. Once i have fixed a few more issues i will push a new version to NPM

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Buffers in Node.js - DigitalOcean
A buffer is a space in memory (typically RAM) that stores binary data. In Node.js, we can access these spaces of memory with...
Read more >
node/buffer.md at main - GitHub
The Buffer class is a subclass of JavaScript's Uint8Array class and extends it with methods that cover additional use cases. Node.js APIs accept...
Read more >
Node.js v19.3.0 Documentation
Buffers and character encodings; Buffers and TypedArrays; Buffers and iteration; Class: Blob ... Usage; Node-API version matrix; Environment life cycle APIs.
Read more >
Creating a Secure Node.js REST API - Toptal
In this article, Toptal JavaScript Developer Marcos Henrique da Silva shows how to create a simple and secure REST API for user management...
Read more >
gRPC service in Node.js: Tutorial, Examples and Best practices
The client uses the protocol buffer to get a service and then connect to it ... It enables us to create gRPC service...
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