ReferenceError: Can't find variable: __fbBatchedBridge - node.js

Using just the default code from react-native init AwesomeProject, when I run the app I get the 'ReferenceError: Can't find variable: __fbBatchedBridge (line 1 in the generated bundle)'.
And, when I 'Reload JS', the app just has the white background rather than any 'hello world' views. I haven't touched any of the code from the init.
Any ideas how to resolve the error?
Screenshot (click to view full size):
Using:
Ubuntu 15.10, 64-bit
Node.js v5.3.0
reactive-native v0.1.7
Nexus 5X, API 6.0.1

I generally see this when the packager hasn't started. Ensure that is running by running react-native start

I had the same issue while using Visual Studio Android Emulator. When the red screen shows up type in the command line
adb shell input keyevent 82
This will trigger the shake event and launch the dev menu
Then hit Dev Settings > Debug server host & port for device and enter <your ip adress>:8081. If for some reason you cannot type in the field you can trigger the text action in the command line by using
adb shell input text <your ip adress>:8081

i solved it using this command
adb reverse tcp:8081 tcp:8081

Thank you rmevans9 and Anonsage for your answers!
I am using HTC One on Ubuntu and there is no menu option, anyway this is the summary of the answers that worked for me:
Create the project
$ react-native init MyProject
$ cd MyProject/
In first console tab run and leave it running as you develop (react-native start alternative):
$ npm start
In second console tab compile and install the project (connect the device to the USB if you want):
$ react-native run-android
Fix ReferenceError: Can't find variable: __fbBatchedBridge:
Find you local ip address by executing ifconfig on Linux/Mac, for example:
inet addr:192.168.0.3
Shake the device to see menu options while app is running (if you don't have "Menu" button)
Go to Dev Settings -> Debug server host & port for device in Debugging section and copy your local ip address with the specific port:
192.168.0.3:8081 (the port can be viewed when running npm start from the first tab)
then go/press Back
Shake the device to see menu options again and press Enable Live Reload (to see changes live when editing)
Shake the device to see menu options again and press Reload JS

This worked for me according to documentation
http://facebook.github.io/react-native/docs/running-on-device-android.html#content
Using adb reverse
Note that this option is available on devices running android 5.0+ (API 21).
Have your device connected via USB with debugging enabled (see paragraph above on how to enable USB debugging on your device).
Run adb reverse tcp:8081 tcp:8081
You can use Reload JS and other development options with no extra configuration
Then Run react-native run-android which will automatically start dev server on 8081 port on your dev machine if not already running.

I encountered this when I had specified different react native versions in my packages.json and my build.gradle file. Making sure they matched, running npm update, and rebuilding from android studio fixed the issue for me.

I had the same problem.
As I followed all the steps mentioned in other answers, I could not resolve the issue.
In my case the firewall was blocking the packets coming from android.

Also If you have submitted your app for the iTunes store, also make sure that your jsCodeLocation is back to the localhost, as shown bellow:
jsCodeLocation = [NSURL URLWithString:#"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
/**
* OPTION 2
* Load from pre-bundled file on disk. The static bundle is automatically
* generated by "Bundle React Native code and images" build step.
*/
//jsCodeLocation = [[NSBundle mainBundle] URLForResource:#"main" withExtension:#"jsbundle"];

Related

Angular9 ng-serve access outside localhost

Being able to serve my application to a couple of friends over a VPN network.
Configuration 1:
OS:Slackware x64
Node:13.13.0 --- built from source.
Npm: 6.14.4
ng: 9.1.1
ts: 3.8.3. (although the project uses 3.7.5)
Configuration 2:
OS: Win10 64bit
Node:12.16.2 -- next,next,finish.
Npm: 6.14.4 (possibly?)
ng: 9.1.1
ts: 3.8.3. (although the project uses 3.7.5)
Test devices:
Android smartphone (v5 series)
Windows 8.1 x64
Windows 10 x64 All three devices are connected to the same VPN my Configuration 1 and
Configuration 2 are connected to
Iphone on its' own mobile internet connection, connected through VPN to me
Windows 7 machine from another location, also connected only through the VPN
Results with Configuration 2:
when using ng serve --host vpn.address.x.y --port custom --disable-host-check
It works flawlessly for all three devices
Results with Configuration 1:
when using ng serve --host vpn.address.x.y --port custom --disable-host-check
Other than running locally, I can run it successfully from test device 1 (Android smartphone), test device 2 (Win8.1) and test device 4 (Iphone)
but on the Win10 machine, I get a "Loading failed for module with source.... and an error :12:1
On test device 5(Win7) I get the same issue as on Win10
What I already tried:
Building v12.16.2 version on the Configuration 1 (linux)
Just unzipping the node binaries for 12.16.2
Both attempts produced the same result as the current 13.13.0 node I compiled from source, so I hope it's not related to node.
I ALSO tried:
passing --host 0.0.0.0
passing --host my_local_IP
passing --host my_external_IP
passing --port 4200
passing --port 8080
passing --port 49000+ (random numbers, really)
These adjustments changed nothing for either Configuration 1 nor Configuration 2 (on 1, it didn't change for the better, on 2 it didn't change for the worse)
Changing browsers didn't change anything for either configuration either. If it works, it works on all browsers on the target test device. If it doesn't, it doesn't work on any browser on the target test device.
I'm posting this as an angular question since I tested a simple with-slackware-shipped apache webserver on the problematic Win10 machine and that webserver is accessible from that Win10 machine.
(The famous "It works!" message is shown)
UPDATE:
I tested using
ng build
ng build --prod
and then serving the output folder of that command as the directory from which my httpd should serve from.
Results are consistent: If it works otherwise, it works with this as well. If not, then not.
I'm evermore steering away from a possible angular-related connectivity issue to perhaps an issue with windows, perhaps? Only Windows (7 and 10, although not 8.1) failed, while iOS and Android did not?
Any insight or a nudge in any direction will be appreciated. I possibly overlooked something.
Please note, both configurations are on the same laptop machine, so there are no hardware discrepancies, only software.

Remote debugging nodejs app in Intellij with Docker - port already allocated

I want to start debugging node.js app using Intellij and node.js interpreter running on Docker. While running the app works, when I try to debug I get the error:
Error running 'index.js'
com.github.dockerjava.api.exception.InternalServerErrorException:
{"message":"driver failed programming external connectivity on
endpoint focused_poincare
(a17137973880d1be7c6a74fc142184fdda31e0dec8ebd539b09d9dbe4cf70014):
Error starting userland proxy: Bind for 0.0.0.0:55578 failed: port is
already allocated"}
Remote interpreter was configured acccording to the documentation. I have created a new Node.js Run/Debug configuration and entered the following data:
.
What might be the cause for debugging not working?
I use:
Intellij Idea Ultimate v. 2019.1.4 Preview
Intellij NodeJS plugin v. 191.7479.1, NodeJS remote interpreter plugin v. 191.6014.8 and Docker plugin v. 191.7141.44
Docker Desktop Community v. 2.0.0.3
EDIT: Adressing the comments:
Local debugging works. The file (index.js) that I am trying to run consists only of console.log('Hello world!') so I don't spawn any child processes on my own. My host system has Windows 10 Pro as OS, so for checking the open ports on host system I used netstat -an | find "55578", which returned nothing. Moreover, if I try to run docker manually from the command line, using docker run -it -p 55578:55578 node, everything runs and no error is given.
Also, each time I try remote debugging, the port number given by Intellij in an error message seems to be random high port number. I tried looking for open ports just after getting error message, but never found one that is open with a number reported by Intellij and those indeed appear in the output:
My Run/Debug configuration:
My Docker configuration (I had to check "Expose daemon on tcp://localhost:2375 without TLS" in Docker configuration to make Intellij and Docker play together):
EDIT: When I add --inspect-brk=0.0.0.0:55432 as "Node Parameters" in "Run/Debug Configurations" Intellij windows (per this bug report) the container nad program start, but debugging seems to be no-op (e.g. the program does not stop on breakpoints).
After updating to Intellij v. 2019.2 I was able to get the container debugging to work using the workaround already mentioned in my question.
I have added a parameter --inspect-brk=0.0.0.0:55432 to Node parameters option in Run/Debug configuration (see the picture below) and everything seems to be working, including the breakpoints.

Connecting to Localhost on Mac from Another Mac: Websocket Issues?

I have a node.js web app running on http://localhost:3000/ on my iMac. I am able to log on to that web app from Chrome on my MacBook using the Wi-Fi IP address of my iMac (found in System Preferences->Network) and the port my web app is running on:
http://10.0.0.37:3000
When using this technique, is there any reason why a websocket would fail in calling a service on a distant server?
Thanks in advance to any thoughts!
It turns out nothing was wrong with websockets. The camera on my MacBook was deactivated for some reason, and that was causing errors from the service I was accessing. I was able to reactivate the camera using instructions from this page:
Quit all apps that you are trying to use with the Camera > Open
Terminal (find in /Applications/Utilities) > copy and paste the
following command then hit the Enter key > Type administrator password
hit Enter.
sudo killall VDCAssistant
if still at the terminal, issue the following command:
sudo killall AppleCameraAssistant

How do I add -http-proxy to an android emulator launch from Android Studio 2.0

I have a local dev web server running on a machine sitting next to me.
I use a hosts file locally on my laptop to map an url to the machine and apparently the android emulator uses NAT and can't resolve the url.
I wanted to configure the emulator to use Charles Proxy for all Internet traffic so that it will go through my laptop and pick up my hosts file for name resolution.
The instructions here say I need to set -http-proxy.
How do I do that if I launch from Android Studio 2.0?
Run emulator from command line
emulator -avd <avd name> -http-proxy ip:port
emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888
Windows
%UserProfile%\AppData\Local\Android\sdk\tools\emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888
BTW
I wasn't able to make a proxy work for me.
There other alternatives The best way to review Android HTTP connections:
OKHtttp Logging Interceptor - logs in logcat, good for Retrofit
Flipper https://fbflipper.com/ - nice UI and modern multiplatform approach
Network Profiler - build into Android Studio, but I never made it work
Stetho http://facebook.github.io/stetho - allows to display all android device/emulator requests/responses in Google chrome developer tools (deprecated but still works well)
Open the Android emulator, go to mobile data settings, change the APN and insert there ip and port of your proxy.
From now on, all the data in/out of the emulator will go through your proxy.
I tried above steps but it was not coming. Finally the command prompt worked.
emulator -avd <avd name> -http-proxy http://CharlesIP address:8888/

debugging node.js with node-inspector

I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code.
I'm using the following,
Node.js : v0.10.26
Express : 4.0.0
Node Inspector : v0.7.3
Google Chrome version : 34.0.1847.131
This is what I'm doing to start the debugger..
$ node-inspector
Node Inspector v0.7.3
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
In another console,
$ node --debug app.js
debugger listening on port 5858
$
Then started Google Chrome and went to
http://127.0.0.1:8080/debug?port=5858
It opens up node-inspector but without any code..all windows are empty.
Noticed that I'm not getting 'Express server listening on port 3000'
Tried all as per node-inspector fails to connect to node but no luck
Couldn't work out what I'm missing. Would be great of you have any suggestions..so I can debug my Node.js apps in Google Chrome.
Try to run node --debug-brk app.js instead of just --debug. Your application may not be pausing before node inspector hooks into the node process. Using --debug-brk will force node to break on the first line of your app and wait for a debugger to attach to the process. Loading the node-inspector web interface is what causes node-inspector to attach to your node process; that's why you include the node debug port in the query string (localhost:8080/debug?port=5858). You're telling node-inspector what port it should reach out and attach to.
Here's an animated gif I put together showing a complete install and run of node-inspector.
In the gif I use the --debug flag because I'm not debugging any code that runs right at startup. I'm debugging inside a request handler, which only fires when the page is requested. Thus, refreshing the page causes node-inspector to break on that line.
I also put together a 15 minute YouTube tutorial a while ago.
http://youtu.be/03qGA-GJXjI
node-inspector by default tries to pre-load all the code before initiating the debug window. I have had instances, node-inspector just hangs for ever because of this pre-loading. Luckily the newer versions have an option to stop the pre-load thereby making the inspector load faster.
Try node-inspector --no-preload
Standard remote debugging is broken entirely in node 6.5. It's replaced however by a new internal node feature
$ node --inspect --debug-brk build/server/server.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/#62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
Debugger attached.
See here - http://arveknudsen.com/?p=346%3Fpage_id%3D346&print=pdf - for more info
--debug-brk is now deprecated
try node --inspect-brk <your starting file name>
and then go to chrome and type url
chrome://inspect and click on Open dedicated DevTools for Node,
the debugger will start, no need of node-inspector
On the left of Node Inspector, "Sources" tab, there is "a box with a triangle in it" - highlighting says "Show Navigator". (See it in the picture above). Open that to find the files you want to debug, and put a break point on code that has yet to run.
Also note, if you want to debug code that runs on starting node, you'll need to use the --debug-brk option when starting. Then, in Node Inspector, you you'll have to kick off the app (F8 to run all). You'll need this option if you want to debug all the initialization code, like starting a web browser.
node-debug --no-preload app.js
This what's working for me. Accoriding to this:
My script runs too fast to attach the debugger.
The debugged process must be started with --debug-brk, this way the
script is paused on the first line.
Note: node-debug adds this option for you by default.

Resources