Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove direct usage of Buffer #93

Closed
VictorPuga opened this issue Nov 9, 2023 · 0 comments · Fixed by #94
Closed

Remove direct usage of Buffer #93

VictorPuga opened this issue Nov 9, 2023 · 0 comments · Fixed by #94

Comments

@VictorPuga
Copy link
Contributor

When using this package in a Next.js application, it seems like Webpack is adding the buffer node module so it is available in the browser.

This package only uses the Buffer class to verify if an object is one of such kind, and it doesn't use any other functions, so it can be a good idea to use an alternative that won't include the buffer module in the bundle.


To reproduce the issue:

Create a Next.js application from a template with Webpack's bundle analyzer

# Create app
yarn create next-app --example analyze-bundles analyze-bundles-app

# Navigate to the directory
cd analyze-bundles-app

# Install the module
yarn add serialize-error

Update pages/index.tsx to use the module

import { NextPage } from "next";
import { serializeError } from "serialize-error";
import { useState, useEffect } from "react";

const Index: NextPage<void> = () => {
  const [err, setErr] = useState(null);

  useEffect(() => {
    setErr(serializeError(new Error("This is an error")));
  }, []);

  return (
    <div>
      <h1>Test Page</h1>
      <div>{JSON.stringify(err)}</div>
    </div>
  );
};

export default Index;

Make a production build with the analyzer plugin

yarn analyze

When the reports are created, open .next/analyze/client.html and see that the buffer module is included in the bundle

bundle-with-buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant