Expo: Can't find variable require - react-native

Dear stackoverflow community,
I'm not able to find any solution online for my problem. My error is the following:
Can't find variable: require
http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:5:24
global code#http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:701:3
Screenshot Expo Error
It was working perfectly 2 days ago, and (apparently) I didn't change anything since then.
Do you have any idea where it can come from?
I'm using:
expo#~3.0.10
react-native "https://github.com/expo/react-native/archive/sdk-38.0.0.tar.gz"
Very basic configuration. I'm suspecting some kind of miss configuration...
Thanks in advance!
Regards,
Guillaume
Updates 09-02-2020 4pm20:
I tried cleaning caches,
I tried changing directory,
I tried expo init a new app, importing the sources of the previous app, installing dependencies, it worked until I ran expo start -c, then the problem came back,
Still working on it...
Updates 09-02-2020 7pm:
I finally succeed to make it work.
Update expo-cli to the latest version
Initialize a new expo app in another directory
Copy/paste source code
Use expo start -c instead of expo start to make sure no cache is involved in the following steps
Install dependencies one by one to make sure none is the problem
Finally test the app

try by adding, import React from 'react' in the file where you mentioned require

first : expo r -c ,
then : npm start,
finally: use require function

Related

React native (Expo) project shows "cant find variable : require"

I am an intermediate react developer.
I was running my react native app peacefully without any problems untill one morning, i did not change anything in my codebase but when i tried to run the app through expo client, it started showing the error in the screenshot.
I have checked and checked this platform, and not a single solution.
I am currently using expo sdk 43 (managed workflow) please help...this is my first time posting here.
This is the error below;
Can't find variable: require
http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:5:24.globalcode#http://127.0.0.1:19000/node_modules /expo/AppEntry.bundle?platform=android&dev=true& hot=false&minify=false:720:3.
Click here for the screenshot of the error
I got it fixed.
See what i did,
I created a fresh expo project using "expo init"
Then copied all my files into the new project "except node_modules and .expo folders".
Then i ran "npm install"
Viola!!! Everything works fine now
Note: i tried removing "node_modules" before over and over again and it dint work.
The only thing that worked was starting a new project and following the above steps.

TypeError: global.__reanimatedWorkletInit is not a function. (In 'global.__reanimatedWorkletInit(_f)', 'global.__reanimatedWorkletInit' is undefined)

TypeError: global.__reanimatedWorkletInit is not a function. (In 'global.__reanimatedWorkletInit(_f)', 'global.__reanimatedWorkletInit' is undefined)
I am using React Native (not expo). I don't even have reanimated downloaded. I had it downloaded then I removed it and rebuilt the app, and it's giving me this error now.
Things I've tried:
deleting node_modules and re-running yarn install
-git reset HEAD~ to a prev commit where I didn't install the reanimated2 packages
I just followed the below steps to solve this issue.
step1: npx react-native run-android
step2: npm start -- --reset-cache
and it solved
Ok, what I ended up doing to solve this was:
-just deleted the whole repo from my local
-cloned it again from github
-uninstalled the app from Android emulator
Then it seemed to work. So maybe it was an error related to cache or something lingering around even after I had removed all instances of the word/package "reanimated" from the whole codebase.
Using Expo in a bareworkflow
Clear app memory
run expo start --dev-client --clear
I solved my issue doing this:
https://github.com/wcandillon/react-native-redash/issues/395
On top you just have to do this: import 'react-native-reanimated';
on your app or index file.
I have tried all the solutions from stack Overflow. (Not working)
Here is the fix:
first check your version for react-native-reanimated and then see the actual documentation of the right version for the configuration.
I am using version 2.4.1 and have solved by this link
I had a require cycle warning from a git submodule inside the src folder which I thought wasn't doing any harm but turns out fixing that solved this issue. I am unsure why the require cycle was causing so much grief but I guess if you've got a require cycle in your output try solving that and it may fix this.
What I did was degrading react-native-reanimated to ^2.6.0. It solved the issue for me.
I had this problem too and simply moved the babel plugin react-native-reanimated/plugin to the last place in the babel's config as stated in the doc.
I should probably mention it worked for me before but when I started migrating the react-native app for web this was the problem for me. I am using expo. I had to run expo with --clear CLI arg as expo start --dev-client --clear.
I Just solved this issue by doing these steps:
close Metro bundler
run this command
npm start -- --reset-cache
react-native start --reset-cache
rebuild the project again

I am building an app using Expo but for some reason all of a sudden the 'npm' start command no longer works

I am fairly new to React Native. I am building a basic app using expo-cli. I don't have a deep understanding on how it works, but I've been following tutorials online on how to use it. Today, I was working on it and used 'npm start' command to launch the expo portal so I could demo my app on a virtual machine but it says it can no longer find the link to the .json file. Can someone please help me to get it working again.
Looks like you're one directory up? Try cd WhatsUp and then run npm start again.

Task :app:compileDebugJavaWithJavac FAILED

I've tried looking for a way to solve this error. It's occurring to me while I try to install my app with react-native run-android.
Already took a look at the solutions from this thread, but my project isn't named native, ./gradlew clean from the android folder didn't work, and I tried deleting the .gradle folder. I've also tried my own simple solutions that sometimes work for whatever reason - uninstalling the app from my phone before re-running react-native run-android and reopening VSCode.
This error started occurring after I installed react-native-unimodules, following the android instructions. A potential problem I see from this is just that react-native-unimodules is supposed to be for Expo and I'm doing things with React Native CLI, but from what I understood, this is allowed.
My react-native version is 0.61.5, react-native-cli is 2.0.1.
Edit:
build.gradle file, as requested.
Also, I don't know if it's relevant, but since it was part of one of the suggested answers, I'll mention this as well: in the gradle.properties file,
android.useAndroidX=true and android.enableJetifier=true were already present.
This is a pretty common case, but what ive figured out during my app building, these steps always helped.
First you need to add below lines in gradle.properties file
android.useAndroidX=true
android.enableJetifier=true
Then after that you need to install, jetfier via either yarn or npm like :
npm i jetifier // first this then the below
npx jetify
After that again re-bundle your code and then run, hope it helps. Feel free for doubts

React-native init issue for new app

I have been going through the react-native tutorial and ran
react-native init AwesomeApp as detailed in the FB page.
After many trials and errors in setting the correct permissions and path I was able to get the app running on IOS.
Awesome app is in a directory Projects
Now I want to create my own app in the same Projects folder and when I try
react-native init newApp I get
Looks like React Native project already exists in the current
folder. Run this command from a different folder or remove node_modules/react-native
I tried from a different folder and still get the same message.
What's the best way to resolve this, deleting the node_modules/react-native or is there another solution and why the same error in a different folder?
Had the same issue, the solution wasn't obvious and I find it nowhere on the Internet so I'm leaving it here.
You may have installed react-native globally. While you should install react-native-cli globally.
Having the first one installed makes typical react-native commads work (starting an app, linking native modules). The only difference is that init fails with above message. And IIRC calling react-native without arguments reveals the source of the problem with descriptive message that you've globally installed wrong package.
Edit:
On Windows also make sure to use CMD, not PowerShell. PowerShell was calling react-native binary (instead of react-native-cli) from SOMEWHERE (I don't know the source, I don't have it available globally, I removed every single globally installed package and it was still calling it (probably from some locally insalled copy)).
React Native development caused another issues too (can't remember the details, sorry) when used with Powershell, so just stick to CMD on Windows.
You were probably still in the AwesomeApp directory while running react-native init newApp.
Try cd .. back to the Projects directory and run react-native init newApp again.
You will then see newApp directory is created inside the Projects directory.
This error occurs when it is in a folder that you deleted. Try to cd to another folder, and it will work.
In the directory C:\\Users\YourUserName you have a file "nodemodules" and a file named "MyProjectName" .
you should delete nodemodules file.
it works for me!
I ran into this too, Make sure your folder does not have any node modules, if problem persists then install react-native-cli again globally using
yarn add global react-native-cli and then initialize your project.
using react-native init {name}.
I had the same error because in some parent directory was backuped "node_modules" directory.
Error resolved by rename it.
Hello for everyone this problem gonna be solved by became sudo user in your Mac if you're using macbook now. Then start to create your project one more time.
Thanks