fix(sourcemap): crc32 is not a function on Node.js < 20.15 (CLI-34F) - #1643
Merged
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
BYK
approved these changes
Sep 28, 2026
BYK
marked this pull request as ready for review
September 28, 2026 12:33
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sentry issues: CLI-34F, CLI-34B (same crash, split into two groups)
Fixes CLI-34F
Fixes CLI-34B
Root cause
src/lib/sourcemap/zip.tsimportscrc32fromnode: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 firstZipWriter.addEntry()throws:I reproduced this on a real Node v20.11.1 by bundling
zip.tsto CJS (the npm build's output format) and writing an archive with it.Fix
New
src/lib/crc32.tsexports acrc32that useszlib.crc32when it exists and otherwise falls back to a table-driven implementation of the same IEEE 802.3 polynomial. The sourcemapZipWriternow imports it instead ofnode:zlib'scrc32. Supported Node versions keep the native implementation.The same bundle on Node v20.11.1 now writes the archive, and
unzip -treports every entry's CRC as OK.Tests
test/lib/crc32.property.test.ts: the fallback matcheszlib.crc32on 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: mocksnode:zlibwithoutcrc32and checks thatZipWriteroutput passesunzip -t. Without the fix it fails withTypeError: crc32 is not a function.vitest run test/lib test/commands test/types test/script: 9988 passed, 1 failed. The failure isdelta-upgrade.mocked.test.ts, which also fails onorigin/mainin this environment and is unrelated.biome checkandtsc --noEmitpass.Not in this PR
src/lib/build/zip-writer.ts(sentry build upload) also importszlib.crc32and 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.