MathieuAuclair
MathieuAuclair

Reputation: 1327

How to solve expo-cli request entity too large?

Every time I start my expo project with yarn start I get the following error once my android device tries to upload and launch the app.

Android Bundling complete 288ms
AsyncStorage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-async-storage/async-storage' instead of 'react-native'. See https://github.com/react-native-async-storage/async-storage
PayloadTooLargeError: request entity too large
    at readStream (/usr/local/lib/node_modules/expo-cli/node_modules/raw-body/index.js:155:17)
    at getRawBody (/usr/local/lib/node_modules/expo-cli/node_modules/raw-body/index.js:108:12)
    at read (/usr/local/lib/node_modules/expo-cli/node_modules/body-parser/lib/read.js:77:3)
    at jsonParser (/usr/local/lib/node_modules/expo-cli/node_modules/body-parser/lib/types/json.js:135:5)
    at call (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:239:7)
    at next (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:183:5)
    at remoteDevtoolsCorsMiddleware (/usr/local/lib/node_modules/expo-cli/node_modules/@expo/dev-server/src/middleware/remoteDevtoolsCorsMiddleware.ts:31:3)
    at call (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:239:7)
    at next (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:183:5)
    at serveStatic (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/serve-static/index.js:75:16)
› Stopped server
Done in 378.28s.

I tried both upgrading/downgrading my version of expo-cli, but to no avail. This issue is occurring since we migrated to eas build system for expo.

What's the solution to avoid android throwing an exception entity too large when transferring the build to the device?

Upvotes: 1

Views: 2244

Answers (1)

MathieuAuclair
MathieuAuclair

Reputation: 1327

According to the following GitHub issue, you may manually fix the package responsible for the crash. Open the following file in your favorite file editor with sudo

sudo vim /usr/local/lib/node_modules/expo-cli/node_modules/raw-body/index.js

Then look for the function declaration of readStream where you'll override the limit value for either a custom value or null for no limit.

function readStream (stream, encoding, length, limit, callback) {
  var complete = false
  var sync = true

  limit = null; // Set custom limit for all payload

  // check the length and limit options.
  // note: we intentionally leave the stream paused,
  // so users should handle the stream themselves.
  if (limit !== null && length !== null && length > limit) {
    return done(createError(413, 'request entity too large', {
      expected: length,
      length: length,
      limit: limit,
      type: 'entity.too.large'
    }))
  }

  //...
}

With that being said, this is only a workaround, and a better solution should be proposed.

Upvotes: 3

Related Questions