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

[0.56] undefined is not an object (evaluating '_this._setComponentRef.bind') #20588

Closed
3 tasks done
reedyrm opened this issue Aug 9, 2018 · 26 comments
Closed
3 tasks done
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@reedyrm
Copy link

reedyrm commented Aug 9, 2018

Environment

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 802.04 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.10.0 - ~/.nvm/v8.10.0/bin/node
Yarn: 1.9.2 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/v8.10.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
Build Tools: 23.0.1, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.2, 27.0.3, 28.0.0
API Levels: 23, 24, 25, 26, 27
IDEs:
Android Studio: 3.1 AI-173.4670197
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
react-native-git-upgrade: 0.2.7

Description

I recently upgraded my project from RN 0.55.2 to RN 0.56.0 and ran into following error. I was able to track it down to Animated.View. It first appeared in a library that I was using (react-navigation), but I was able to reproduce it with just a single item.

I noticed that earlier in RN 0.56.0 there were similar errors:

I tried to solve the problem using some of the linked solutions and was not able to make any progress.

Could there be an issue with https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/createAnimatedComponent.js#L39 due to babel 7 changes?

image

TypeError: undefined is not an object (evaluating '_this._setComponentRef.bind')

This error is located at:
    in AnimatedComponent (at App.js:7)
    in App (at renderApplication.js:32)
    in RCTView (at View.js:43)
    in RCTView (at View.js:43)
    in AppContainer (at renderApplication.js:31)

AnimatedComponent
    index.bundle?platform=ios&dev=true&minify=false:45418:56
constructClassInstance
    index.bundle?platform=ios&dev=true&minify=false:20994:32
updateClassComponent
    index.bundle?platform=ios&dev=true&minify=false:22561:35
performUnitOfWork
    index.bundle?platform=ios&dev=true&minify=false:25090:27
workLoop
    index.bundle?platform=ios&dev=true&minify=false:25123:47
renderRoot
    index.bundle?platform=ios&dev=true&minify=false:25156:21
performWorkOnRoot
    index.bundle?platform=ios&dev=true&minify=false:25717:23
performWork
    index.bundle?platform=ios&dev=true&minify=false:25649:30
performSyncWork
    index.bundle?platform=ios&dev=true&minify=false:25624:20
requestWork
    index.bundle?platform=ios&dev=true&minify=false:25530:26
scheduleWork
    index.bundle?platform=ios&dev=true&minify=false:25392:28
scheduleRootUpdate
    index.bundle?platform=ios&dev=true&minify=false:25920:21
render
    index.bundle?platform=ios&dev=true&minify=false:26375:26
renderApplication
    index.bundle?platform=ios&dev=true&minify=false:64535:59
run
    index.bundle?platform=ios&dev=true&minify=false:64209:28
runApplication
    index.bundle?platform=ios&dev=true&minify=false:64259:28
__callFunction
    index.bundle?platform=ios&dev=true&minify=false:2630:49
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:2407:31
__guard
    index.bundle?platform=ios&dev=true&minify=false:2583:15
callFunctionReturnFlushedQueue
    index.bundle?platform=ios&dev=true&minify=false:2406:21

Reproducible Demo

https://github.com/reedyrm/react-native-bind-undefined/tree/broken-animated-view

@EyMaddis
Copy link

EyMaddis commented Aug 9, 2018

The issue seems to be that the definition of the flow type for _setComponentRef not only defines the type but also initializes the value with undefined.

This is probably a babel setup error, most likely around@babel/preset-flow and/or @babel/plugin-proposal-class-properties.

EDIT
I found this: babel/babel#8417

@scriptum
Copy link

scriptum commented Aug 13, 2018

babel/babel#8417 (comment) + cleaning /tmp/metro-cache resolved this issue for me.

@krzysztof-miemiec
Copy link

I was also struggling for hours with this issue, and the @babel/plugin-transform-flow-strip-types plugin helped. My babel.config.js:

module.exports = {
  'presets': [
    'module:metro-react-native-babel-preset',
    'module:react-native-dotenv',
  ],
  'sourceMaps': true,
  'plugins': [
    '@babel/transform-flow-strip-types',
    '@babel/proposal-class-properties',
    '@babel/proposal-object-rest-spread',
    '@babel/transform-runtime'
  ],
};

Credits for solution to #20150 (comment)

@kennethnym
Copy link

This worked for me. Thank you!

@aerielcruz
Copy link

I was also struggling for hours with this issue, and the @babel/plugin-transform-flow-strip-types plugin helped. My babel.config.js:

module.exports = {
  'presets': [
    'module:metro-react-native-babel-preset',
    'module:react-native-dotenv',
  ],
  'sourceMaps': true,
  'plugins': [
    '@babel/transform-flow-strip-types',
    '@babel/proposal-class-properties',
    '@babel/proposal-object-rest-spread',
    '@babel/transform-runtime'
  ],
};

Credits for solution to #20150 (comment)

@krzysztof-miemiec Should I create a new babel.config.js file? or could add it to my .babelrc file?

@krzysztof-miemiec
Copy link

@aerielcruz I had to replace my .babelrc with babel.config.js, because Jest didn't play well with Babel 7 using .babelrc. You can check if .babelrc works for you, and if it won't, try babel.config.js 😉

@aerielcruz
Copy link

@krzysztof-miemiec Thanks! Will try it out 😄

@tcodes0
Copy link

tcodes0 commented Oct 3, 2018

Babel 7 here, react-native 0.57.1. My error looks like this. It started messing with me after I touched my babel config briefly. Trying fixes in thread...

FIXED: added @babel/plugin-transform-flow-strip-types, placed first in plugins array in .babelrc

screen shot 2018-10-03 at 9 18 55 am

@seeya
Copy link

seeya commented Oct 15, 2018

Babel 7 here, react-native 0.57.1. My error looks like this. It started messing with me after I touched my babel config briefly. Trying fixes in thread...

FIXED: added @babel/plugin-transform-flow-strip-types, placed first in plugins array in .babelrc

screen shot 2018-10-03 at 9 18 55 am

Thanks, worked for me too.

@dani-PYT
Copy link

@seeya can you show your .babelrc file?

@seeya
Copy link

seeya commented Oct 16, 2018

@seeya can you show your .babelrc file?
My babel.rc.

{ 
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
        ["@babel/plugin-transform-flow-strip-types"],
        ["@babel/plugin-proposal-decorators", { "legacy": true}],
        ["@babel/plugin-proposal-class-properties", { "loose": true}]
    ]
}

And my version of dependencies are as follows

  "dependencies": {
    "babel-plugin-transform-flow-strip-types": "^6.22.0",
    "mobx": "^5.5.0",
    "mobx-react": "^5.2.8",
    "mobx-state-tree": "^3.5.0",
    "native-base": "^2.8.1",
    "react": "16.5.0",
    "react-native": "0.57.1",
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/plugin-proposal-decorators": "^7.1.2",
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.48.0",
    "react-test-renderer": "16.5.0"
  }

If fails, react-native start --reset-cache do this. It worked for me.

@kalahooo
Copy link

If tips above do not help, try to clean cache.

@leshphonc
Copy link

If tips above do not help, try to clean cache.

How to clean cache

@seeya
Copy link

seeya commented Oct 24, 2018

If tips above do not help, try to clean cache.

How to clean cache

try this

react-native start --reset-cache

@jasonComing
Copy link

these are the steps I have taken to resolve this issue in Windows

1. Close emulator
2. Kill all node.exe proccess
3. remove all files in temp
4. remove node_modules
5. install babel-plugin-transform-flow-strip-types
6. npm install
7. react-native start --reset-cache
8. react-native run-android

@seasparta618
Copy link

these are the steps I have taken to resolve this issue in Windows

1. Close emulator
2. Kill all node.exe proccess
3. remove all files in temp
4. remove node_modules
5. install babel-plugin-transform-flow-strip-types
6. npm install
7. react-native start --reset-cache
8. react-native run-android

this really did help! Thanks!

@joncursi
Copy link
Contributor

I hit this error using @babel/preset-flow. Had to remove the preset and instead use @babel/plugin-transform-flow-strip-types.

@flacito
Copy link

flacito commented Nov 29, 2018

For iOS,adding @babel/plugin-transform-flow-strip-types and then cleaning the build dir in XCode.

@drborges
Copy link

drborges commented Dec 4, 2018

Same here. Make sure you reset the cache after adding @babel/plugin-transform-flow-strip-types.

$ react-native --version
react-native-cli: 2.0.1
react-native: 0.57.5

.babelrc

{
  "presets": [
    "module:metro-react-native-babel-preset"
  ],
  "plugins": [
    ["@babel/plugin-transform-flow-strip-types"],
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}

@reedyrm reedyrm closed this as completed Dec 5, 2018
facebook-github-bot pushed a commit that referenced this issue Dec 10, 2018
Summary: There are some versions of babel 7's flow support that cause problems with property initializers. I changed this code to use class properties to fix the issue. See #20588

Reviewed By: TheSavior

Differential Revision: D13396959

fbshipit-source-id: a76266ac0c8a6a19a1c45f7136de4aba9c72581d
@tangliang1
Copy link

tangliang1 commented Dec 18, 2018

My .babelrc is also this, and all the dependencies are latest.

{ 
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
        ["@babel/plugin-transform-flow-strip-types"],
        ["@babel/plugin-proposal-decorators", { "legacy": true}],
        ["@babel/plugin-proposal-class-properties", { "loose": true}]
    ]
}

If still wrong, try react-native start --reset-cache
that works for me. thanks @seeya

@TyLy83
Copy link

TyLy83 commented Dec 18, 2018

thank @tangliang1 for point this out.

@tr3v3r
Copy link

tr3v3r commented Jan 16, 2019

Try:
"watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && yarn cache clean"

Worked for me

@18945168
Copy link

Babel 7 here, react-native 0.57.1. My error looks like this. It started messing with me after I touched my babel config briefly. Trying fixes in thread...

FIXED: added @babel/plugin-transform-flow-strip-types, placed first in plugins array in .babelrc

screen shot 2018-10-03 at 9 18 55 am

i have the problem because of i use 'react-navigation', when i remove 'react-navigation' its run ok, this is work for me, to add the plugin --> @babel/plugin-transform-flow-strip-types

@igor90007
Copy link

"mobx": "4.9.2",
"mobx-react": "5.4.3",
"react-native": "0.58.6",
works for me

@ShaubertIlya
Copy link

Those who not solved this issue. Try to run react-native start in terminal before react-native run-android or ios. In my case it was all about node js window

@unadlib
Copy link

unadlib commented Apr 25, 2019

Thank you so much, I almost gave up using react navigation.

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

No branches or pull requests