vercel / vercel/next.js

Unexpected bundle Buffer ployfill into client chunks

Open
#40,178 15 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Verify canary release
  • I verified that the issue exists in the latest Next.js canary release
Provide environment information

Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
Binaries:
Node: 16.15.1
npm: 8.11.0
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.2.5
eslint-config-next: 12.2.5
react: 18.2.0
react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

A typeof Buffer check, for example:

const isNode = typeof Buffer !== 'undefined';
console.log({ isNode });

It causes a full Buffer ployfill (22.51Kb) to be put into the client bundle.

Expected Behavior

A typeof Buffer check should just return 'undefined' in browsers instead.

Link to reproduction

https://github.com/chentsulin/nextjs-issue-40178-bundle-client-buffer

To Reproduce

Add the following lines to the pages/index.js file:

const isNode = typeof Buffer !== 'undefined';
console.log({ isNode });

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction and the added code in pages/index.js, then inspect the generated client bundle to confirm how the typeof Buffer check is handled. Done means the browser check returns undefined without including the full Buffer polyfill in the client chunks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, node.js
Domain
build-system, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.