react-native: undefined is not an object (evaluating 'regeneratorRuntime.mark')

Is this a bug report?

Yes (write your answer here)

Have you read the Bugs section of the Contributing to React Native Guide?

(Write your answer here.)

Environment

  1. react-native -v: 0.45.1
  2. node -v: 8.1.3
  3. npm -v: 5.0.4
  4. yarn --version (if you use Yarn): 0.27.5

Then, specify:

  1. Target Platform (e.g. iOS, Android): Android
  2. Development Operating System (e.g. macOS Sierra, Windows 10): macOS Sierra 10.12.5
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant): Android SDK 25, Android Build Tools 25.0.2

Steps to Reproduce

(Write your steps here:)

  1. react-native init AwesomeProject
  2. react-native run-android

Expected Behavior

Should work as it did with RN v0.44.0 or RN 0.45.0 (Write what you thought would happen.)

Actual Behavior

undefined is not an object (evaluating 'regeneratorRuntime.mark')
<unknown>
    
loadModuleImplementation
    require.js:174:12
guardedLoadModule
    require.js:126:36
_require
    require.js:110:24
<unknown>
    index.js:2
loadModuleImplementation
    require.js:174:12
guardedLoadModule
    require.js:126:36
_require
    require.js:110:24
<unknown>
    configureStore.js:19
loadModuleImplementation
    require.js:174:12
guardedLoadModule
    require.js:126:36
_require
    require.js:110:24
<unknown>
    index.js:32
loadModuleImplementation
    require.js:174:12
guardedLoadModule
    require.js:126:36
_require
    require.js:110:24
<unknown>
    index.android.js:10
loadModuleImplementation
    require.js:174:12
guardedLoadModule
    require.js:119:45
_require
    require.js:110:24
global code
   
screen shot 2017-07-05 at 22 42 33

(Write what happened. Add screenshots!)

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 53
  • Comments: 92 (23 by maintainers)

Commits related to this issue

Most upvoted comments

Found the problem what I had (with new project generated with Ignite).

The error were pointing in my project to line import rootSaga from '../Sagas/' which contain export like this:

export default function * root () {
  yield [
    // ... snip ....
  ]
}

After changing it to this started to work:


const root = function * root () {
  yield [
    // .... snip ....
  ]
}
export default root

I’m not yet familiar with the ES6 generator functions and require support for them, but at least now I can continue. And have to say that the error were pointing to the place where the invalid export were. I hope this helps someone.

@vongohren Double make sure you reset the packager, Im using react-native 0.46.1 and babel at 2.0.0 all good on both platforms Debug/Release builds. Please make sure you run

watchman watch-del-all
rm -rf ./node_modules
rm -rf $TMPDIR/react-*
npm i babel-preset-react-native@2.0.0 -D -S
npm install
npm start -- --reset-cache
react-native run-ios

Also make sure you reset your android/ios emulator/simulator, delete both android/ios build folders.

I’m using react-native 0.48.3 and what fixed it for me is the following steps:

  1. I created a .babelrc file with the following contents in the root of the project
{
  "presets": ["react-native"]
}
  1. I installed babel-preset-react-native@3.0.2
  2. I ran node node_modules/react-native/local-cli/cli.js start --reset-cache

The problem is now gone.

Another workaround pointed by Markus in https://github.com/facebook/react-native/issues/14933 which doesnt require downgrade the babel preset is to use variables so

instead of

function* foo() {}

do

const foo = function* foo() {}

Face same problem when creating new project with Ignite.

  • react-native -V 0.45.1
  • node -v v7.10.0
  • npm -v 4.2.0
  • yarn --version 0.27.5
  • react-native run-ios

@Amurmurmur suggestion didn’t help.

@ide That version seems to work great! Thanks for publishing it!

@kcalmes Make sure you reset react-native packager after you’ve downgraded babel with:

npm start -- --reset-cache

@brentvatne Thanks for reopening this!

If I’m understanding the commits @shenjunru posted correctly (thanks!) this is what I think has happened:

https://github.com/facebook/react-native/commit/3103258ca0fd2fb0fda0da1120d9cdf4baf0ca05 Removed the global for regeneratorRuntime https://github.com/facebook/react-native/commit/e7c1cf5b7d2eba9468804635d0c2a0fc6725e42a added a new babel transformer which should have added the require("regeneratorRuntime") where needed, however, this plugin adds in after the var _marked = regeneratorRuntime.mark(...); line, leading to the error.

I know absolutely nothing about babel transformers, but I would imagine this means that the fix needs to be in the babel-preset/transforms/transform-regenerator-runtime-insertion.js file.

If no one with some experience of babel is able to take this up, I can give it a go, but it might take me a bit of research.

@grabbou @GantMan @ernoaapa Alright guys, figured out the problem downgraded babel-preset-react-native form 2.1.0 to 2.0.0 all works fine on Android/iOS Though once upgraded to 0.46 the error comes back. As for RN 0.47-rc.0, most packages I have linked, wont work due to some changes to the api of the react-native I guess because they will throw errors such as:

:react-native-blur:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/amurmurmur/exampleapp/node_modules/react-native-blur/android/src/main/java/com/cmcewen/blurview/BlurViewPackage.java:23: error: method does not override or implement a method from a supertype
    @Override
    ^
Note: /Users/amurmurmur/exampleapp/node_modules/react-native-blur/android/src/main/java/com/cmcewen/blurview/BlurringView.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
:react-native-blur:compileReleaseJavaWithJavac FAILED

@mjesun I have just opened a PR (#15584) which reverts that commit and removes the unnecessary transformer. Hopefully, this is correct and fixes the issue!

hello! this seems to be a problem for everyone using redux-sagas, I don’t use it and I don’t really touch this part of the code so if someone wants to fix it, that would be great. please include a unit test in the fix so it doesn’t regress in the future.

Downgrade babel-preset-react-native to 2.0.0 work for me too. But why 2.1.0 don’t work?

Hello @brentvatne, this issue is apparently always present… Consider its re-opening please : )

Thanks for confirming, everyone. I published babel-preset-react-native@3.0.2 (dist-tag = latest) as well as v2.0.1 with this fix.

I published babel-preset-react-native@3.0.2-rc.0 with the latest code. Please try it out and if it’s working well we can publish 3.0.2.

This issue caused by commits:

  • e7c1cf5b7d2eba9468804635d0c2a0fc6725e42a added a new babel transformer (babel-preset/transforms/transform-regenerator-runtime-insertion.js)
  • 3103258ca0fd2fb0fda0da1120d9cdf4baf0ca05 cherry-pick of 361f03badb2080c009080312bbf45a7372b6a387 removed global.regeneratorRuntime. But, this commit has been reverted.

This code will be inserted by babel. And the order of variables causes the undefined issue.

var _marked = regeneratorRuntime.mark(...);
var regeneratorRuntime = require("regenerator-runtime"); // inserted by the new transformer

The solution is use babel-preset-react-native <= 2.0.0

Alright seems like I’ve managed to fix this on RN 0.45.1 Just clean everything:

watchman watch-del-all
rm -rf $TMPDIR/react-*
rm -rf yarn.lock
rm -rf ./node_modules
yarn install

Worked for me, also unlinking and linking might help.

@fengshuo thanks, but already tried and didn’t work. I’m with Expo create-react-native-app, maybe it adds some to this issue

In RN 0.47.1 even just doing this:

function* upAsyncWorker(action: UpAsyncAction) {
/// ...
}

Without an export is causing this error. I fixed it by doing the const trick above. So this works now:

const upAsyncWorker = function* upAsyncWorker(action: UpAsyncAction) {
/// ...
}

For me, using yarn instead of npm was the only thing that worked.

watchman watch-del-all
rm -rf ./node_modules
rm -rf $TMPDIR/react-*
npm cache clean
yarn cache clean
yarn install
yarn start -- --reset-cache
react-native run-ios

I also downgraded babel-preset-react-native to 2.0.0, so I’m not sure if it was the combination or just switching to yarn.

Please note that this also error might also happen with old code (react native 0.44 and about as old babel-preset-react-native) if using Node >= 9.

A fix is to use any Node <9 version which might be a lot easier than upgrading react native.

@Manuelandro update to babel-preset-react-native 2.0.1 or 3.0.2

The only question I have is that, the const way of exporting sagas, going to be the standard now? Or next babel-present release will fix that ?

@SudoPlz node node_modules/react-native/local-cli/cli.js start --reset-cache + “the sagas export refactoring” work for me !! 😁

"babel-preset-react-native": "^4.0.0",`
"react-native": "^0.50.4",
"react": "16.0.0"

I ran into this error using babel-preset-expo and fixed it by switching to babel-preset-react-native:

yarn add babel-preset-react-native

in .babelrc:

"presets": [
    "babel-preset-react-native"
  ]

I’m still having this issue, even after following all of the solutions presented in this thread, including @Amurmurmur 's solution and resetting my terminal / local server, even resetting my computer. It started happening for me after I moved my project root from my user folder to my documents, but the issue persists even if it’s moved back so I’m not sure that’s the cause.

I can’t help but notice my main.jsbundle in xcode is red, which usually indicates it’s missing. I’d try to re-add it to my project, but I can’t find any resources online that indicate where the main.jsbundle is.

Here’s my full Xcode log:

undefined is not an object (evaluating 'regeneratorRuntime.mark')
2017-09-13 11:47:23.171 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: undefined is not an object (evaluating 'regeneratorRuntime.mark')
2017-09-13 11:47:23.176 [info][tid:com.facebook.react.JavaScript] Running application "APP" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2017-09-13 11:47:23.176 [error][tid:com.facebook.react.JavaScript] Application APP has not been registered.

Hint: This error often happens when you're running the packager (local dev server) from a wrong folder. For example you have multiple apps and the packager is still running for the app you were working on before.
If this is the case, simply kill the old packager instance (e.g. close the packager terminal window) and start the packager in the correct app folder (e.g. cd into app folder and run 'npm start').

This error can also happen due to a require() error during initialization or failure to call AppRegistry.registerComponent.


2017-09-13 11:47:23.197 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: Application APP has not been registered.

Hint: This error often happens when you're running the packager (local dev server) from a wrong folder. For example you have multiple apps and the packager is still running for the app you were working on before.
If this is the case, simply kill the old packager instance (e.g. close the packager terminal window) and start the packager in the correct app folder (e.g. cd into app folder and run 'npm start').

This error can also happen due to a require() error during initialization or failure to call AppRegistry.registerComponent.

Currently running on the latest version of React Native (0.48.3) and the latest babel-preset-react-native (3.0.2).

Also to address the registration complaint, my app has been running fine on previous versions of React Native and I haven’t changed the registration code in either my index.ios.js or my index.android.js.

My index.ios.js and index.android.js:

import {
  AppRegistry,
} from 'react-native';

import Home from "./src/Home";

AppRegistry.registerComponent('APP', () => Home);

This should be correct, yeah? So I have no clue why it’s suddenly getting this complaint too. Although I suspect it’s the result of the first error undefined is not an object (evaluating 'regeneratorRuntime.mark')

@fengshuo @webwelten I believe you are going to have to wait and see if this gets updated in SDK 21, or forbabel-preset-expo to get updated… or you can try and not use the default crna .babelrc and set the preferred babel preset. You will have to account for @expo/vector-icons though; see this comment and the one below it.

@matt-oakes Commit 3103258ca0fd2fb0fda0da1120d9cdf4baf0ca05 has been reverted. So the regeneratorRuntime became global again. And commit e7c1cf5b7d2eba9468804635d0c2a0fc6725e42a (transform-regenerator-runtime-insertion) is not necessary anymore.

@vongohren Indeed the fresh project will work for you however once you start using babel features such as export/import you will face the problem with babel-preset-react-native 2.1.0 This is a relevant issue #14933

Downgrading worked for me, but I’d also like to know what the issue actually is and what a real fix is.

That did the trick, I previously deleted the node_modules dir, but I didn’t realize I missed the other cache. Thanks for your help @Amurmurmur!