Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing Poly (babel-polyfill,core.js symbol,es6-symbol) Crashes app on load - Objects are not valid as React child #18542

Closed
3 tasks done
Harag opened this issue Mar 24, 2018 · 26 comments
Labels
Bug Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.

Comments

@Harag
Copy link

Harag commented Mar 24, 2018

There might be something to learn from this issue even if it is not the same maybe its a similar loading issue?
#15182

I tried to use Symbol in my local project but none of the poly's I found work they all crash RN when I try to run even the simplest app with Objects are not valid as React child
reconcileChIldFibers throws InvalidObjectType line 8348:31 (ReactNativeRenderer - dev.js)

Environment

Environment:
OS: Linux 4.15
Node: 8.10.0
Yarn: 1.5.1
npm: 5.6.0
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found

Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.3
react-native: 0.54.2 => 0.54.2

Steps to Reproduce

react-native init rnsymboleish
cd rnsymboleish
npm install --save babel-polyfill (or npm install --save es6-symbol)
npm install

---App.js

import 'babel-polyfill';   //---> or //'es6-symbol/implement' //'core-js/es6/symbol';
import React, { Component } from 'react';
import { Text, View} from 'react-native';
  
export default class App extends Component {
  render() {
    return (
      <View>
        <Text>
          Eish
        </Text>
      </View>
    );
  }
}

react-native run-android

Expected Behavior

Thought it would not crash...?

Actual Behavior

3-24 19:14:45.728 30769 31013 I ReactNativeJS: Running application "rnsymbolwtf" with appParams: {"rootTag":1}. DEV === true, development-level warning are ON, performance optimizations are OFF
03-24 19:14:45.748 30769 31013 E ReactNativeJS: Invariant Violation: Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead.
03-24 19:14:45.748 30769 31013 E ReactNativeJS:
03-24 19:14:45.748 30769 31013 E ReactNativeJS: This error is located at:
03-24 19:14:45.818 30769 31013 E ReactNativeJS: Invariant Violation: Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead.
03-24 19:14:45.818 30769 31013 E ReactNativeJS:
03-24 19:14:45.818 30769 31013 E ReactNativeJS: This error is located at:

@react-native-bot react-native-bot added the Platform: Linux Building on Linux. label Mar 24, 2018
@kelset
Copy link
Contributor

kelset commented Mar 25, 2018

Why are you writing

<--View-->
        <--Text-->
          Eish
        <--/Text-->
      <--/View-->

Instead of

	  <View>
        <Text>
          Eish
        </Text>
      </View>

@Harag
Copy link
Author

Harag commented Mar 26, 2018

@kelset sorry the code that looked like html tags was disappearing even with a pre tag and I did a quick hack just to get it to display. I see now that you use <pre><code> combination... will try that to prevent confusion going forward

@kelset
Copy link
Contributor

kelset commented Mar 26, 2018

Does it mean that now it works for you? If so, can you please close the issue?

@Harag
Copy link
Author

Harag commented Mar 26, 2018

@kelset NO it does not work the funny code was github issue tracker giving me issues displaying code in comments the funny code has nothing to do with the actual error.

@Harag
Copy link
Author

Harag commented Mar 26, 2018

Edited the original comment to clear up any confusion.

@ronhe
Copy link
Contributor

ronhe commented Apr 18, 2018

Moving import 'core-js/es6/symbol'; to the top of index.js solved the problem for me.

@ujwal-setlur
Copy link

@ronhe, moving it to the top of the file did not work for me, unfortunately :-(

@ujwal-setlur
Copy link

By the way, this was working for me up until react-native 0.55.4. With rn-0.56.0, I see this problem.

@stale
Copy link

stale bot commented Oct 5, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 5, 2018
@zedtux
Copy link
Contributor

zedtux commented Oct 9, 2018

I have the same issue since I migrated to RN 0.57.

Adding import 'core-js' in the index.js file of the project, at line 1, solved the error.

Why adding this import is solving this error?

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 9, 2018
@FibreFoX
Copy link

@zedtux OMG thanks so much !!! After spending at least two days debugging my application to the latest RN version, you safed me with that code!

I was suspecting react-native-firebase because of this issue looking close enough: invertase/react-native-firebase#1438

Adding import 'core-js/es6/symbol'; only did not work for me, but adding import 'core-js'; made the trick ... probably because Symbol was not working as expected and maybe because another polyfill is required. This even is mentioned here: #15902 (comment)

While "debugging" the app it works like a charm, which even got mentioned in a different project: realm/realm-js#1883 even there an JSC-upgrade was mentioned.

@sayali181290
Copy link

@zedtux : This solution gives me an error as follows :

Unable to resolve module ./$.html from /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/core-js/modules/es5.js: The module ./$.html could not be found from /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/core-js/modules/es5.js. Indeed, none of these files exist:

  • $.html
  • /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/core-js/modules/$.html/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)

Error: Unable to resolve module ./$.html from /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/core-js/modules/es5.js: The module ./$.html could not be found from /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/core-js/modules/es5.js. Indeed, none of these files exist:

  • $.html
  • /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/core-js/modules/$.html/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:209:697)
    at ResolutionRequest.resolveDependency (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:83:16)
    at DependencyGraph.resolveDependency (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/node-haste/DependencyGraph.js:238:485)
    at Object.resolve (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/lib/transformHelpers.js:180:25)
    at dependencies.map.result (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/DeltaBundler/traverseDependencies.js:311:29)
    at Array.map ()
    at resolveDependencies (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/DeltaBundler/traverseDependencies.js:307:16)
    at /Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/DeltaBundler/traverseDependencies.js:164:33
    at Generator.next ()
    at step (/Users/sayalideshpande/Documents/Projects/KOA/KOA Conference App/node_modules/metro/src/DeltaBundler/traverseDependencies.js:266:307)

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:bundleReleaseJsAndAssets'.

Process 'command 'node'' finished with non-zero exit value 1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 19s
35 actionable tasks: 1 executed, 34 up-to-date

@zedtux
Copy link
Contributor

zedtux commented Oct 31, 2018

@sayali181290 what RN version are you using?

@sayali181290
Copy link

0.57

@zedtux
Copy link
Contributor

zedtux commented Oct 31, 2018

I'm using this version too, it should come from one of your dependencies. Can you please post your package.json file?

@sayali181290
Copy link

Yes. Sure.

{
"name": "KOA",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"firebase": "^4.9.1",
"rc-swipeout": "^2.0.11",
"react": "16.5.0",
"react-native": "0.57.1",
"react-native-actionsheet": "^2.4.2",
"react-native-dropdownalert": "^3.7.0",
"react-native-elements": "^0.19.1",
"react-native-gridview": "^0.1.2",
"react-native-image-picker": "^0.26.10",
"react-native-keyboard-aware-scroll-view": "^0.7.4",
"react-native-material-dropdown": "^0.11.1",
"react-native-material-textfield": "^0.12.0",
"react-native-modal-dropdown": "^0.6.2",
"react-native-pages": "^0.7.0",
"react-native-qrcode": "^0.2.7",
"react-native-segmented-control-tab": "^3.3.1",
"react-native-snap-carousel": "^3.7.5",
"react-native-super-grid": "^2.4.3",
"react-native-swipe-list-view": "^1.3.1",
"react-native-tag-input": "0.0.21",
"react-native-tag-select": "^2.0.0",
"react-native-vector-icons": "^5.0.0",
"react-navigation": "^2.16.0",
"rn-fetch-blob": "^0.10.13"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.46.0",
"path": "^0.12.7",
"react-test-renderer": "16.5.0",
"ws": "3.3.2"
},
"jest": {
"preset": "react-native"
}
}

@sayali181290
Copy link

Please share if anyone having any solution for this

@FibreFoX
Copy link

FibreFoX commented Oct 31, 2018

@sayali181290 instead of adding polyfills, and as this is android-specific, I went over to add the JSC-android I mentioned above:

  1. adding to your project-dependencies
yarn add --dev jsc-android
  1. modify your android/build.gradle file
allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

        // for replacing the older JavaScriptCore which is bundled with RN (they use r174650)
        maven {
            // Local Maven repo containing AARs with JSC library built for Android
            url "$rootDir/../node_modules/jsc-android/dist"
        }
    }
}
  1. modify your android/app/build.gradle file (I added it below the dependencies-block)
configurations.all {
    resolutionStrategy {
        eachDependency { DependencyResolveDetails details ->
            if (details.requested.name == 'android-jsc') {
                details.useTarget group: details.requested.group, name: 'android-jsc-intl', version: 'r225067'
            }
        }
    }
}

Note on step 3: you should make sure that the version matches the folder below /node_modules/jsc-android/dist/org/webkit/android-jsc-intl/ in order to match the maven-repository file-structure.

Note in general: this is a workaround and replaces the used JavaScriptCore which comes with RN itself. It will increase your filesyse of the created APK-files (like mentioned on the android-jsc project)

@ManishAhire
Copy link

@FibreFoX I tried the above solution but not working

@FibreFoX
Copy link

@ManishAhire Did you remove the import of core-js ? I can't remember if I had that included AND having the newer core... maybe they are conflicting each-other

@ronhe
Copy link
Contributor

ronhe commented Dec 28, 2018

I'm not sure why, or if it's better than just adding all of core-js polyfills as @zedtux suggested, but adding the map polyfill import before the symbol one also works for me on [email protected] + Android API 26.

import 'core-js/es6/map';
import 'core-js/es6/symbol';

@cpojer
Copy link
Contributor

cpojer commented Jan 29, 2019

It seems like there are enough workarounds for this to consider the issue resolved.

@cpojer cpojer closed this as completed Jan 29, 2019
@FibreFoX
Copy link

@cpojer so instead of fixing a hole in the wall, you just say, we shouldn't look there? As this is an issue with the bundled polyfills required due to some older JSC, maybe with upcoming releases of the new JSC this issue gets resolved (which are getting into RN with 0.59 maybe?).

Can we please re-open this issue until it gets verified to work with the new JSC, or with adjusted polyfills?

@cpojer
Copy link
Contributor

cpojer commented Jan 30, 2019

React Native is not shipping with a Symbol polyfill right now and we aren't going to. You are right, with a new version of JSC the Symbol polyfill will be available and this problem should go away. It will be in the next version.

@Lucashuang0802
Copy link

any news on this issue? it has been blocking me from upgrading react-native from 0.56 to 0.57.8

@RatherLogical
Copy link

RatherLogical commented Mar 27, 2019

I fixed this issue by updating core-js to the latest stable and changing my polyfills.ts to this.

import 'core-js/es/symbol';
import 'core-js/es/object';
import 'core-js/es/function';
import 'core-js/es/parse-int.js';
import 'core-js/es/parse-float.js';
import 'core-js/es/number';
import 'core-js/es/math';
import 'core-js/es/string';
import 'core-js/es/date';
import 'core-js/es/array';
import 'core-js/es/regexp';
import 'core-js/es/map';
import 'core-js/es/weak-map';
import 'core-js/es/set';

Here's the error I was getting.
image

@facebook facebook locked as resolved and limited conversation to collaborators Jan 29, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests