Large JS bundle: Request body larger than maxBodyLength

I have a large codebase (>100Mb) and it seems that expo fails to upload the JS bundle to its CDN.
Here’s the error that I’m getting when running expo publish

Building optimized bundles and generating sourcemaps...
Starting Metro Bundler
Finished building JavaScript bundle in 26994ms.

Bundle                     Size
┌ index.ios.js           104 MB
├       104 MB
├      68.8 MB
└  68.8 MB

💡 JavaScript bundle sizes affect startup time. Learn more.

Analyzing assets
Saving assets
No assets changed, skipped.

Processing asset bundle patterns:
- /Users/vels/vdev/zreader/zreader/**/*

Uploading JavaScript bundles
Request body larger than maxBodyLength limit
Error: Request body larger than maxBodyLength limit
    at RedirectableRequest.write (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/node_modules/follow-redirects/index.js:98:24)
    at RedirectableRequest.end (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/node_modules/follow-redirects/index.js:117:8)
    at dispatchHttpRequest (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/lib/adapters/http.js:272:11)
    at new Promise (<anonymous>)
    at httpAdapter (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/lib/adapters/http.js:20:10)
    at dispatchRequest (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/lib/core/dispatchRequest.js:59:10)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at ApiV2Client._requestAsync (/@expo/xdl@59.0.19/src/ApiV2.ts:232:18)
    at ApiV2Client.uploadFormDataAsync (/@expo/xdl@59.0.19/src/ApiV2.ts:184:12)
    at _uploadArtifactsAsync (/@expo/xdl@59.0.19/src/Project.ts:873:10)

I’ve tried downgrading the expo-cli to 4.1.3 (saw an issue about it), but it didn’t help.
I even tried increasing the maxBodyLength in follow-redirects, but this makes the expo servers return 413 error:

data: 208183555, max: 536870912
Request failed with status code 413
Error: Request failed with status code 413
    at createError (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/Users/vels/.nvm/versions/node/v12.18.0/lib/node_modules/expo-cli/node_modules/axios/lib/adapters/http.js:237:11)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Any chance I can build and publish a bundle of this size?


Expo CLI 4.1.3 environment info:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
      Node: 12.18.0 - ~/.nvm/versions/node/v12.18.0/bin/node
      npm: 6.14.11 - ~/.nvm/versions/node/v12.18.0/bin/npm
      CocoaPods: 1.10.0 - /usr/local/bin/pod
      iOS SDK:
        Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
      Android SDK:
        API Levels: 30
        Build Tools: 30.0.2
        System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android Studio: 4.1 AI-201.8743.12.41.7042882
      Xcode: 12.4/12D4e - /usr/bin/xcodebuild
      expo: ~40.0.0 => 40.0.0
      react: 16.13.1 => 16.13.1
      react-dom: 16.13.1 => 16.13.1
      react-native: => 0.63.2
      react-native-web: ~0.13.12 => 0.13.18
      expo-cli: 4.1.3
    Expo Workflow: managed


I was able to solve this issue with expo export --public-url, which means that I will need to host my bundle and assets outside of Expo CDN.

This is not a terrible solution (thanks to github pages :), but still requires a bit more build and publishing setup than the default expo path.

If you don’t need OTA updates(and for that large bundle you shouldn’t use that either way), you can serve this bundle only during build e.g with ngrok and kill server after. If you decide to do that make sure to disable OTA updates first.

Alternatively, consider refactoring your app, I don’t know what is the reason for that large bundle, but maybe it’s sth you can download in runtime and cache manually in the filesystem? Max Apk size on google play is 100MB, with compression you should be ok, but if this bundle keeps growing you might reach that limit

1 Like

Thank you for the detailed answer.
The app contains a lot of text that is used in the Reader component.
I am planning to export all this text into some kind of an asset or into a local DB since the app is supposed to work offline and I can’t download this text in runtime.

I am still looking for the right solution to do it…

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.