question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"invalid attempt to spread non-iterable instance" error only for android when trying string spread

See original GitHub issue

Environment

React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: x64 Intel® Core™ i7-4870HQ CPU @ 2.50GHz Memory: 809.96 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.9.2 - /usr/local/bin/node Yarn: 1.0.2 - /usr/local/bin/yarn npm: 6.3.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0 Android SDK: Build Tools: 26.0.1 IDEs: Android Studio: 3.1 AI-173.4907809 Xcode: 10.0/10A255 - /usr/bin/xcodebuild npmPackages: react: ^16.5.0 => 16.5.0 react-native: ^0.57.2 => 0.57.2 npmGlobalPackages: create-react-native-app: 1.0.0 eslint-plugin-react-native: 3.2.0 react-native-cli: 2.0.1 react-native-gesture-handler: 1.0.0-alpha.29 react-native-git-upgrade: 0.2.7 react-native-rename: 2.2.2 react-native-vector-icons: 4.4.2

Description

In debug mode everything is working as expected. But after bundling, when using spread operation to convert string to array, only Android (platform independent) throws error. But ios works well (both debug and production). The code was working well before updating RN 55.4 to 57. After update I had to change the code to this working example:

Array.from(str).map((p, i) => {return p;})

Reproducible Demo

Error example:

const str = 'error test';
[...str].map((p, i) => {return p;})

The approach is right but what is the problem with babel 7?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:21
  • Comments:9

github_iconTop GitHub Comments

42reactions
helleroycommented, Oct 29, 2018

We encountered this as well:

  • Works fine in dev-mode on both iOS and Android
  • Works fine with release bundle on iOS
  • Hard crash with release bundle on Android

After some testing we found that setting loose to true for @babel/plugin-transform-spread solves the problem. This indicates that the problem either lies with Babel 7 or with how react-native/metro handles the bundling of Android apps using Babel 7.

"plugins": [
   ["@babel/plugin-transform-spread", {
     "loose": true
   }]
 ]

Doing this may cause problems in other parts of our code though, so we elected not to use it.

In the end we ended up using Array.from(str) instead of [...str] as mentioned in the description. However, considering how this breaks what is literally the first example in the MDN docs, it should probably be looked into.

11reactions
sibeliuscommented, Nov 13, 2018

[...Array(3).keys()] is causing trouble on android as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Invalid attempt to spread non-iterable instance
Here's an example of invalid spread operator use: function trySpread(object) { let array; try { array = [...object]; console.log('No error', ...
Read more >
invalid attempt to spread non-iterable instance in order ...
Well the error message seems pretty clear- it's telling you that you're trying to use the spread operator on something that isn't iterable-...
Read more >
Uncaught TypeError: Invalid attempt to spread non-iterable ...
Hi, We just noticed this error with a repeater in one form – it's the first time we use the pro version so...
Read more >
Invalid attempt to spread non-iterable instance in React ...
Coding example for the question TypeError: Invalid attempt to spread non-iterable instance in React Native-React Native.
Read more >
Invalid Attempt To Spread Non-Iterable Instance
spread refers to . Non-iterable means it is not like a list. The error is saying todos is not like a list or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found