react-native: App force close on release mode: undefined is not an object (evaluating 'e.length')

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS High Sierra 10.13 Node: 8.9.0 Yarn: 1.2.1 npm: 5.5.1 Watchman: 4.7.0 Xcode: Xcode 9.1 Build version 9B37 Android Studio: 3.0 AI-171.4402976

Packages: (wanted => installed) react: ^16.0.0 => 16.0.0 react-native: ^0.50.2 => 0.50.2

Target Platform: iOS (11.1)

Steps to Reproduce

  1. App with React Native v0.50+ installed
  2. Run debug build (works)
  3. Run release build (crash on app open)

Expected Behavior

Not crash

Actual Behavior

Crash on app open with this error: RCTFatalException: Unhandled JS Exception: undefined is not an object (evaluating 'e.length')'

Stack points inside the color-converter package.

Current workaround

  • Downgrade to 0.49.5

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 38
  • Comments: 47 (7 by maintainers)

Most upvoted comments

My solution:

"react-native": "0.50.3",
"react": "^16.0.0",

remove resolutions from package.json

and build steps:

watchman watch-del-all
rm -rf $TMPDIR/react-*
rm yarn.lock
rm android/app/src/main/assets/index.android.bundle
rm android/app/src/main/assets/index.android.bundle.meta
yarn cache clean
yarn install
mkdir -p android/app/src/main/assets/
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
cd android
./gradlew clean
./gradlew assembleDebug
cd ..

Everything ok!

I was able to fix the problem by resolving the color-convert package to use the pull request here: Qix-/color-convert/pull/49

just changed my package.json to include: "resolutions": { "color-convert": "github:zbarbuto/color-convert" }

this is just a workaround though since other packages might declare the same var twice which breaks uglify

TO ANYONE WHO FINDS THEMSELVES HERE: This issue has been resolved with a recent publish to uglify-es npm package. There is no longer a need for any of these hacky workarounds. Simply remove the node_modules/metro-bundler module and npm i, or wipe all your node_modules and npm i (the later is heavier on bandwidth).

This also isn’t directly an issue with metro-bundler or react-native, so this issue can probably be closed.

@thphu Your issue is similar to https://github.com/facebook/react-native/issues/16567

View.propTypes have been deprecated. but some code or dependent package is still using View.propTypes in your project. check it: https://github.com/facebook/react-native/issues/16567#issuecomment-340041357

Same here! 0.50.2

Hi,

I think a have a same issue with @brunolemos when I upgrade my project from react-native 0.45 to 0.50.3, but my error is a bit difference

 Unhandled JS Exception: undefined is not an object (evaluating 'p.View.propTypes.style')', reason: 'Unhandled JS Exception: undefined is not an object (evaluating 'p.View.prop..., stack:
<unknown>@2285:2191
i@2:563
<unknown>@2284:203
i@2:563
<unknown>@2207:402
i@2:563
<unknown>@2201:197
i@2:563
<unknown>@2200:124
i@2:563
<unknown>@1274:1117
i@2:563
<unknown>@301:389
i@2:563
<unknown>@12:38
i@2:563
n@2:267
global code@2833:9
'

I tried to install the latest metro-bundler like @th317erd said, but can’t fix it. PS: debug mode everything is perfect 😦

The root cause is a bug in uglify-js: https://github.com/mishoo/UglifyJS2/issues/2449

Fixed in this pull request: https://github.com/mishoo/UglifyJS2/pull/2458

You can wait for a react-native upgrade or resolve uglify-js from the pull request (temporarily) in your package.json:

"resolutions": {
  "uglify-js": "github:alexlamsl/UglifyJS2#issue-2449"
},

I did some digging around and was able to get it to “work”… Not sure if this is the same change as @dotansimha made or not… So perhaps the issue is actually related to changed made in https://github.com/mishoo/UglifyJS2

I modified the minify function in node_modules/metro-bundler/src/JSTransformer/worker/minify.js file from

  const result = uglify.minify(inputCode, {
    mangle: false,//{ toplevel: true },
    compress:false,
      
    output: {
      ascii_only: true,
      quote_style: 3,
      wrap_iife: true },

    sourceMap: {
      content: inputMap,
      includeSources: false },

    toplevel: true });


  if (result.error) {
    throw result.error;
  }

  return {
    code: result.code,
    map: result.map };

}

to

  const result = uglify.minify(inputCode, {
    mangle: false,//{ toplevel: true },
    compress:false,
      
    output: {
      ascii_only: true,
      quote_style: 3,
      wrap_iife: true },

    sourceMap: {
      content: inputMap,
      includeSources: false },

    toplevel: true });


  if (result.error) {
    throw result.error;
  }

  return {
    code: result.code,
    map: result.map };

}

@brunolemos not working here.

  "dependencies": {
    "@babel/runtime": "^7.1.2",
    "native-base": "^2.8.0",
    "react": "16.5.0",
    "react-native": "0.57.1",
    "react-native-charts-wrapper": "^0.4.8",
    "react-navigation": "^2.17.0"
  },

still crashed on build release. happen when some of native-base componen touched.

Upgraded react-native to the latest version and this is no longer an issue.

In my case, c.View.propTypes.style causes crash.

I run the app in release mode with react-native run-ios --configuration Release for debug it easily and see the report in Crashlytics. Then I see the error and solve it.

@th317erd i think this would be lost on every npm install