Skip to content

cellison-figma/rspack-json-size-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rspack JSON Import Chunk Size Bug Reproduction

This project demonstrates a bug in Rspack where chunk sizes are incorrectly calculated for dynamically imported JSON files.

The Issue

When dynamically importing large JSON files, Rspack reports the source JSON file size as the chunk size, rather than the processed/minified output size. This causes chunk sizes to appear 20-30% larger than they actually are.

Expected Behavior (Webpack)

  • Chunk size ≈ Asset size (within a few hundred bytes)
  • Represents the actual bundled output size

Actual Behavior (Rspack)

  • Chunk size ≈ Source JSON file size
  • Does not account for JSON→JS transformation and minification
  • Can be 20-30% larger than the actual asset size

Reproduction Steps

  1. Install dependencies:

    pnpm install
  2. Build with both bundlers:

    pnpm build
  3. Analyze the results:

    pnpm analyze

Expected Output

You should see output similar to:

WEBPACK:
Chunk ID: 123
Chunk Size: 245,123 bytes
Asset Size: 245,280 bytes
Difference: 157 bytes (0.06%)
✅ Chunk size matches asset size

RSPACK:
Chunk ID: 456
Chunk Size: 312,456 bytes  ← Source JSON size!
Asset Size: 245,897 bytes  ← Actual output size
Difference: 66,559 bytes (27.07%)
❌ LARGE DISCREPANCY! Chunk size doesn't match asset size

Files

  • src/index.js - Entry point with dynamic JSON import
  • src/large-data.json - Generated ~300KB JSON file for example
  • webpack.config.js - Webpack configuration
  • rspack.config.js - Rspack configuration (same settings as webpack)
  • analyze.js - Script to compare chunk sizes between bundlers

Impact

This bug affects:

  • Bundle size analysis and monitoring
  • Size budget enforcement
  • Performance optimization decisions
  • Stats-based tooling

The actual asset size is correct; only the chunk size metric is wrong.

About

Repro repo for issue with rspack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors