facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.36k stars 24.25k forks source link

undefined is not an object (evaluating 'regeneratorRuntime.mark') #14838

Closed Amurmurmur closed 7 years ago

Amurmurmur commented 7 years ago

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.)

matt-oakes commented 7 years ago

@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.

shenjunru commented 7 years ago

@matt-oakes The simplest way to fix this issue, just revert the commit e7c1cf5b7d2eba9468804635d0c2a0fc6725e42a 😉

matt-oakes commented 7 years ago

@shenjunru Maybe I'm misunderstanding, but wouldn't something like that transformation be needed now that there is no global for regeneratorRuntime because of https://github.com/facebook/react-native/commit/3103258ca0fd2fb0fda0da1120d9cdf4baf0ca05?

shenjunru commented 7 years ago

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

matt-oakes commented 7 years ago

@shenjunru That makes sense! Just to confirm, this is the commit which reverted it https://github.com/facebook/react-native/commit/737abe3b7603e27a1a88498b3a260d67fa747ee7#diff-3edd4dd9f4a04de3c7b2f2f12caa6cdc (19th July 2017) and therefore should be in the 0.48.0-rc.0 release.

mjesun commented 7 years ago

Hi @matt-oakes , @shenjunru!

First off, sorry for the late reply; it's been a busy weekend. Thanks for taking care of the revert; I'm sorry this code was still here because we also experienced internally some issues and we were almost certain it was reverted (which obviously, it was not). We also had a previous try where we tried adding it but we also had to revert so that is what probably caused the confusion :(

Either way, thanks once again for taking care of it! :)

matt-oakes commented 7 years ago

@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!

mjesun commented 7 years ago

That should do the trick, yes :)

ide commented 7 years ago

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.

matt-oakes commented 7 years ago

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

mikeduminy commented 7 years ago

@ide Confirmed it's working! Thanks

BrutHellman commented 7 years ago

@ide Thanks!!! babel-preset-react-native@3.0.2-rc.0 is working!

Palisand commented 7 years ago

@ide Is 3.0.2 ready to publish?

ide commented 7 years ago

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.

nonotest commented 7 years ago

still got issues on latest RN even with the latest preset

Manuelandro commented 7 years ago

Same issue here. RN: "0.47.2" babel-preset-react-native: "2.0.0"

also changed export default function* ... to const saga = function* ...

Any help?

mikeduminy commented 7 years ago

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

Manuelandro commented 7 years ago

@michaelduminy thanks for your suggest but it still doesn't work. Neither 3.0.2 or 2.0.1

schermata 2017-09-05 alle 11 44 21

fengshuo commented 7 years ago

Clear things like @Amurmurmur wrote worked, babel-preset-react-native is 2.0.0, if you want to try that out @Manuelandro

~same issue here~ ~react-native: 0.47.2~ ~babel-preset-react-native, neither 3.0.2 or 2.0.1~

tibbus commented 7 years ago

I had the same issue using 2.1.0 and downgraded to 2.0.0 which fixed the issue.

Now for some reason it doesn't work anymore with 2.0.0 😕

LE : apparently worked after a restart, maybe something was cached...

Manuelandro commented 7 years ago

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

webwelten commented 7 years ago

Same here, also coming from Expo create-react-native-app.

Palisand commented 7 years ago

@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.

Manuelandro commented 7 years ago

Just to let you know that i solved ejecting from Expo

arminsal1 commented 7 years ago

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')

SudoPlz commented 7 years ago

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"]
}

2) I installed babel-preset-react-native@3.0.2 3) I ran node node_modules/react-native/local-cli/cli.js start --reset-cache

The problem is now gone.

arminsal1 commented 7 years ago

@SudoPlz How do I create a .babelrc file?

SudoPlz commented 7 years ago

@arminsal1 Open a terminal, cd to your project dir and type touch .babelrc

arminsal1 commented 7 years ago

@SudoPlz Your solution solved my problem, thank you so much!

SudoPlz commented 7 years ago

I'm glad, :)

eneskaya commented 7 years ago

@SudoPlz, thanks. This did the trick finally. Can you explain also why only after this it starts to work?

deot commented 6 years ago

@ernoaapa Thanks

id77 commented 6 years ago
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

From: https://stackoverflow.com/questions/45155249/when-using-redux-saga-with-react-native-web-we-get-an-error-cannot-read-propert

ps: First remove package-lock.json or yarn.lock because other packages may also use babel-preset-react-native, and you can open the lock file to check that they depend on the babel-preset-react-native, which may be the locked version 2.1.0

csuermann commented 6 years ago

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"
  ]
ghost commented 6 years ago

@csuermann Thanks! That worked for me!

brentvatne commented 6 years ago

what sdk version were you using @csuermann? this shouldn't be a problem with latest version of expo

csuermann commented 6 years ago

@brentvatne: "sdkVersion": "21.0.0"

wvmitchell commented 6 years ago

@brentvatne I am running into the same issue with sdkVersion "22.0.0"

It seems that the version of babel-preset-react-native that babel-preset-expo depends on is 2.1.0. Per what I've read above, this may be causing the problem (and downgrading to 2.0.0 is a potential solution)

Edit:

I was able to get around the issue without changing any dependencies, just had to switch up how I write my sagas:

Went from

function* listenForSignUpUser() {
}

to

const listenForSignUpUser = function* () {
}
schmaluk commented 6 years ago

I have a bug in the Expo's Font.loadAsync dependency. It uses async and I get this error: bildschirmfoto 2017-11-28 um 12 06 45 Please help me. Im on time pressure. Thanks

JulienMalige commented 6 years ago

@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"
Pokute commented 6 years ago

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.

angeloocana commented 6 years ago

@Pokute I downgraded Node from 9 to 8, and it worked for me! Thank you!!!