Skip to content

fix(sourcemap): crc32 is not a function on Node.js < 20.15 (CLI-34F) - #1643

Merged
BYK merged 2 commits into
mainfrom
cursor/fix-sourcemap-zip-crc32-fe99
Sep 28, 2026
Merged

BYK merged 2 commits into
mainfrom
cursor/fix-sourcemap-zip-crc32-fe99

Conversation

@cursor

@cursor cursor Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Sentry issues: CLI-34F, CLI-34B (same crash, split into two groups)

Fixes CLI-34F
Fixes CLI-34B

Root cause

src/lib/sourcemap/zip.ts imports crc32 from node:zlib, but that API only exists on Node.js >= 20.15 / >= 22.2. The npm package accepts older runtimes (engines: >=20.0, and the bundle's version gate allows Node 18+).

Reproduction

On Node.js 20.0–20.14 (both reports are 20.11 / 20.12), run sentry sourcemap upload <dir>, typically through @sentry/bundler-plugins. The first ZipWriter.addEntry() throws:

TypeError: (0 , import_node_zlib.crc32) is not a function

I reproduced this on a real Node v20.11.1 by bundling zip.ts to CJS (the npm build's output format) and writing an archive with it.

Fix

New src/lib/crc32.ts exports a crc32 that uses zlib.crc32 when it exists and otherwise falls back to a table-driven implementation of the same IEEE 802.3 polynomial. The sourcemap ZipWriter now imports it instead of node:zlib's crc32. Supported Node versions keep the native implementation.

The same bundle on Node v20.11.1 now writes the archive, and unzip -t reports every entry's CRC as OK.

Tests

  • test/lib/crc32.property.test.ts: the fallback matches zlib.crc32 on random bytes, continuing from a previous checksum matches hashing the concatenation, and the standard check value ("123456789" → 0xCBF43926) holds.
  • test/lib/sourcemap/zip.mocked.test.ts: mocks node:zlib without crc32 and checks that ZipWriter output passes unzip -t. Without the fix it fails with TypeError: crc32 is not a function.
  • vitest run test/lib test/commands test/types test/script: 9988 passed, 1 failed. The failure is delta-upgrade.mocked.test.ts, which also fails on origin/main in this environment and is unrelated.
  • biome check and tsc --noEmit pass.

Not in this PR

src/lib/build/zip-writer.ts (sentry build upload) also imports zlib.crc32 and has the same latent problem on these Node versions. There are no Sentry reports for that path yet, so it's left for a follow-up that switches it to this helper once this lands.

Open in Web View Automation 

…I-34F)

The sourcemap ZipWriter imported crc32 from node:zlib, which only exists on
Node.js >= 20.15 / >= 22.2. The npm package accepts Node.js 18+, so
`sentry sourcemap upload` (e.g. via the bundler plugins) crashed in
addEntry with "TypeError: crc32 is not a function" on older runtimes.

Add a crc32 helper that uses zlib.crc32 when present and otherwise falls
back to a table-driven implementation of the same polynomial, and use it
in the sourcemap ZipWriter.

Fixes CLI-34F
Fixes CLI-34B

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
@vercel

vercel Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Sep 28, 2026 1:31pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Sep 28, 2026 1:31pm UTC

Request Review

@BYK
BYK marked this pull request as ready for review September 28, 2026 12:33
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 28, 2026
Comment thread packages/cli/src/lib/sourcemap/zip.ts
@vercel
vercel Bot temporarily deployed to Preview – sentry-local September 28, 2026 13:31 Inactive
@BYK
BYK merged commit bfbd57b into main Sep 28, 2026
37 checks passed
@BYK
BYK deleted the cursor/fix-sourcemap-zip-crc32-fe99 branch September 28, 2026 13:40

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 91b778b4 Deployed Sep 28, 2026 by vercel[bot]
Preview – sentry-local — 91b778b4 Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants