react-native: [0.57] _this._registerEvents is not a function on a clean project

Environment

$ react-native info

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
      Memory: 520.12 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/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
    IDEs:
      Xcode: 10.0/10L232m - /usr/bin/xcodebuild
    npmPackages:
      react: 16.5.0 => 16.5.0 
      react-native: 0.57.0 => 0.57.0 
    npmGlobalPackages:
      create-react-native-app: 1.0.0
      react-native-cli: 2.0.1

Description

Bumped an existing 0.56.1 project to 0.57 and encountered an error on simulator start: _this._registerEvents is not a function on a clean project. Tried a new project from scratch and got the same error. Running Xcode 10 Beta.

Same error was mentioned in the following ticket: #20712

screen shot 2018-09-13 at 12 21 14
_this._registerEvents is not a function. (In '_this._registerEvents()', '_this._registerEvents' is undefined)

WebSocket
    index.bundle?platform=ios&dev=true&minify=false:24147:28
connectToDevTools
    index.bundle?platform=ios&dev=true&minify=false:26078:62
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:25863:38
loadModuleImplementation
    index.bundle?platform=ios&dev=true&minify=false:262:14
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:19771:20
loadModuleImplementation
    index.bundle?platform=ios&dev=true&minify=false:262:14
guardedLoadModule
    index.bundle?platform=ios&dev=true&minify=false:150:47
global code
    index.bundle?platform=ios&dev=true&minify=false:81797:4
****

Reproducible Demo

xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
react-native init AwesomeProject
cd AwesomeProject
node_modules/.bin/react-native run-ios

EDIT: Tried another new project and it worked this time. I guess it must be related to caching issues.

Will reopen if I can reliably reproduce.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 25
  • Comments: 25 (1 by maintainers)

Most upvoted comments

#20567 by kelset

  1. add the metro-react-native-babel-preset package
  2. change .babelrc to { “presets”: [“module:metro-react-native-babel-preset”] }
  3. npm run start --reset-cache or react-native start -reset-cache

it has been 1,5 year that I am coding with react-native. what i learned in this long time.

  1. dont touch your released code
  2. never mind doing something new

'cause all I have is these fc.g bugs with no solution.

react-native start --reset-cache worked for me on @hbicexp solution

got the same issue.

my react-native version is “0.59.4” and have same issue

Never mind. The problem was fixed but after about 30 mins it’s back and this time the above solution is not working. I even tried gradlew clean and npm cache clean.

Update: I removed everything from .babelrc and left an empty object and now the app works perfectly. Even after ~1.8 years of development in react-native, I have no idea about what is going on. :\

We updated to React Native 0.57.4 and @babel/core 7.1.2 and our problem went away.

I’m also facing this issue on version 0.60.5

Error screenshot

react-native info:

System:
    OS: Windows 10
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
    Memory: 1.10 GB / 7.88 GB
  Binaries:
    Node: 12.9.0 - C:\Users\GUSTAV~1.MAX\AppData\Local\Temp\yarn--1567529680393-0.3427366134530774\node.CMD
    Yarn: 1.17.3 - C:\Users\GUSTAV~1.MAX\AppData\Local\Temp\yarn--1567529680393-0.3427366134530774\yarn.CMD
    npm: 6.10.2 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5791312

package.json

{
  "name": "HomeDoctor",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.6.1",
    "axios": "^0.19.0",
    "babel-plugin-root-import": "^6.4.1",
    "react": "16.8.6",
    "react-native": "0.60.5",
    "react-native-dotenv": "^0.2.0",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-vector-icons": "^6.6.0",
    "react-native-xml2js": "^1.0.3",
    "react-navigation": "^3.12.1",
    "react-redux": "^7.1.1",
    "reactotron-react-native": "^3.6.5",
    "reactotron-redux": "^3.1.1",
    "reactotron-redux-saga": "^4.2.2",
    "redux": "^4.0.4",
    "redux-saga": "^1.0.5"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/runtime": "^7.5.5",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "babel-preset-react-native": "5.0.2",
    "eslint": "^6.2.2",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}

babel.config.js

module.exports = {
  presets: [
    'module:metro-react-native-babel-preset',
    'module:react-native-dotenv',
    'react-native',
  ],
};

I tried: https://github.com/facebook/react-native/issues/21094#issuecomment-422245589 https://github.com/facebook/react-native/issues/21094#issuecomment-435597536 https://github.com/facebook/react-native/issues/21094#issuecomment-504986169 None worked.

Solution:

I removed ‘react-native’ from my babel.config.js and added a parenthesis on the render of App.js instead of making it an object.

Changed it from:

const App = () => {
  <Provider store={store}>
    <Navigation />
  </Provider>;
};

to

const App = () => (
  <Provider store={store}>
    <Navigation />
  </Provider>
);

Facing the same issue.

Requiring module "node_modules/react-native/Libraries/Core/InitializeCore.js", which threw an exception: TypeError: _this._registerEvents is not a function

Tried all the methods mentioned above. This is the output of my react-native info


  React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
      CPU: (4) x64 Intel(R) Core(TM) i3-3217U CPU @ 1.80GHz
      Memory: 330.08 MB / 7.69 GB
      Shell: 4.4.19 - /bin/bash
    Binaries:
      Node: 8.3.0 - ~/.nvm/versions/node/v8.3.0/bin/node
      npm: 5.3.0 - ~/.nvm/versions/node/v8.3.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 24.0.1, 26.0.3, 27.0.3, 28.0.2, 28.0.3
        System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64
    npmPackages:
      react: ^16.8.3 => 16.8.6 
      react-native: ^0.59.10 => 0.59.10 

package.json


{
  "name": "testApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "react-devtools": "react-devtools"
  },
  "rnpm": {
    "assets": [
      "./App/assets/fonts"
    ]
  },
  "dependencies": {
    "adm-zip": "^0.4.11",
    "axios": "^0.17.0",
    "bugsnag-react-native": "^2.22.0",
    "clevertap-react-native": "^0.3.0",
    "js-file-download": "^0.4.1",
    "json5": "^2.1.0",
    "lodash": "^4.17.11",
    "moment": "^2.22.2",
    "native-base": "^2.7.2",
    "plist": "^3.0.1",
    "prop-types": "^15.7.2",
    "query-string": "^6.1.0",
    "react": "^16.8.3",
    "react-file-download": "^0.3.5",
    "react-moment": "^0.6.9",
    "react-native": "^0.59.10",
    "react-native-appsflyer": "1.2.13",
    "react-native-blur": "^3.2.2",
    "react-native-check-box": "^2.1.3",
    "react-native-checkbox": "^2.0.0",
    "react-native-code-push": "^5.6.0",
    "react-native-contacts": "^4.0.0",
    "react-native-cookies": "^3.3.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-document-picker": "^2.1.0",
    "react-native-easy-grid": "^0.2.0",
    "react-native-email-link": "^1.1.0",
    "react-native-exception-handler": "^2.9.0",
    "react-native-extended-stylesheet": "^0.6.0",
    "react-native-fbsdk": "0.8.0",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-firebase": "^5.5.4",
    "react-native-flash-message": "^0.1.11",
    "react-native-google-signin": "^1.0.0-rc6",
    "react-native-htmlview": "^0.13.0",
    "react-native-icon-badge": "^1.1.3",
    "react-native-image-gallery": "^2.1.5",
    "react-native-image-picker": "^0.26.10",
    "react-native-image-preview": "^0.3.1",
    "react-native-image-zoom-viewer": "^2.2.15",
    "react-native-intercom": "^12.0.0",
    "react-native-linear-gradient": "2.4.0",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-mixpanel": "^1.1.1",
    "react-native-modal": "^6.5.0",
    "react-native-modal-selector": "^1.0.3",
    "react-native-modalbox": "^1.6.0",
    "react-native-month-selector": "^1.4.0",
    "react-native-picker-select": "^4.4.0",
    "react-native-prefix-picker": "^2.0.2",
    "react-native-progress": "^3.5.0",
    "react-native-prompt-android": "^0.3.4",
    "react-native-referrer": "^0.1.4",
    "react-native-restart": "0.0.6",
    "react-native-share": "^1.1.3",
    "react-native-signature-capture": "^0.4.9",
    "react-native-simple-radio-button": "^2.7.2",
    "react-native-slider": "^0.11.0",
    "react-native-star-rating": "^1.0.9",
    "react-native-svg": "^5.5.1",
    "react-native-svg-charts": "^2.2.3",
    "react-native-swiper": "^1.5.13",
    "react-native-switch": "^1.5.0",
    "react-native-theme": "^0.1.8",
    "react-native-timer-countdown": "^4.0.5",
    "react-native-vector-icons": "^4.6.0",
    "react-native-version-number": "^0.3.4",
    "react-navigation": "^1.5.13",
    "rn-fetch-blob": "^0.10.13",
    "rn-tooltip": "^1.1.2",
    "victory-native": "^0.15.0",
    "xcode": "^1.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.5.4",
    "@babel/runtime": "^7.5.4",
    "babel-jest": "20.0.3",
    "babel-loader": "^8.0.6",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "babel-preset-react-native": "^5.0.2",
    "jest": "20.0.4",
    "metro-react-native-babel-preset": "^0.55.0",
    "react-devtools": "^3.2.3",
    "react-test-renderer": "^16.8.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

Try commenting out setupDevtools in setUpDeveloperTools. I still haven’t found the underlying issue, but since all I want to upgrade my old project, I will postpone the investigation.

@HuanDay I need to execute it on Android emulator!! I have already tried multiple times: react-native start – --reset-cache.

Did anyone found a solution for this? I am facing the issue for a while now! Cant make new projects cause they show the same error… 😕