Error: Failed to load 'http://localhost:8082/create_session'
besarthoxhaj opened this issue ยท 23 comments
When running the application on dev mode from my phone I get the following error
Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:8082/create_session'
If I run the same code on the simulator it works fine.
Another user hit this here #276. Are you also on android? If so does running adb forward tcp:8082 tcp:8082
fix the issue for you?
Hi @alazier I'm using iOS on mac. Is there some other thing I can do?
There is definitely an issue at the moment running debug mode on the device. We have an rpc server running on the device/simultor to serve api calls when in debug mode - when running on the device chrome is trying to hit localhost rather than the server on the device which fails.
You may be able to hardcode your devices IP address to work around the issue. You can change this by editing the DEVICE_HOST
url in node_modules/realm/lib/rpc.js
. I haven't tested this yet so let us know if this works. We will look into ways of doing this automatically.
I just tried to change DEVICE_HOST
to both:
DEVICE_HOST = '<IP-ADDRESS>:8081';
// and
DEVICE_HOST = '<IP-ADDRESS>:8082';
but I still get the same error Failed to load 'http://<IP-ADDRESS>:8082/create_session'
Do I need to change it somewhere else as well?
Not sure as I haven't had the chance to try this out yet. Will give it a try later today.
Thanks @alazier and also thanks for bringing Realm in react-native!:)
I was able to get chrome debugging working by changing the ip address as described above as well as following the instructions for getting chrome debugging working on device from the react native docs. The steps I took:
- Changed localhost in Appdelegate.m to the computer's IP address
- From this page https://facebook.github.io/react-native/docs/debugging.html I made this change:
On iOS - open the file RCTWebSocketExecutor.m and change localhost to the IP address of your computer. Shake the device to open the development menu with the option to start debugging.
- I changed
const DEVICE_HOST
innode_modules/realm/lib/rpc.js
to use the device IP address.
If you continue to get the same error most likely the device IP address you are using is incorrect.
Sorry for the delay guys, will try this as soon as I got time, hopefully later today.
Would this be the cause for the first error here? -> #303
I am also getting this error with iOS simulator. React Native 0.21.
I have the packager running on a non-standard port (9081)
I'm also getting this in the iOS simulator, React Native 0.20.0. I am using the Chrome Debugger. The packager is listening on port 8081.
I had this error on iOS device and simulator with RN. I found out that I accidentally drag RealmJS.framework to the Embedded Binaries section but not the RealmReact.framework. Fixed this then the error was gone.
@leijing7 Thanks! You saved my time!
I had the same problem and I also dragged RealmJS.framework instead of RealmReact.framework. Now, all works fine for me.
@ Realm developers: thank you for your work!
I suggest to add this problem & its solution to F.A.Q. troubleshooting section..
double checked and definitely got RealmReact.framework in the embedded binaries. Everything works fine when chrome debugging isn't enabled. But as soon as it is -- I get this issue.
@alexcurtis is this only on device for you, or in simulator as well?
@appden I've only tested on the simulator. React Native 0.21. I have the packager running on a non-standard port (9081)
I've had issues with debugging and Realm for a long time. It used to work in the emulator but now I can't debug at all. Of course, that is a huge dealbreaker as debugging is essential.
Is there any chance this will get fixed? Because otherwise, I'm afraid I'll have to replace Realm with another database.
I hit this today runing iOS simulator on Mac.
POST http://localhost:8082/call_method net::ERR_EMPTY_RESPONSE
For me (I am using Expo) the actual reason that this is occurring is that it is being blocked by CORS because the origins don't match
To bypass this problem on the iOS simulator, I am using this workaround to turn off CORS in Chrome:
- Close Chrome if it is already open
-
open -a Google\ Chrome --args --disable-web-security --user-data-dir
Hope that helps anyone stuck on this same issue.
@appden
First complete error from Chrome console:
XMLHttpRequest cannot load http://localhost:8082/create_session.
The 'Access-Control-Allow-Origin' header has a value 'http://localhost:8081' that is not equal to the supplied origin.
Origin 'http://localhost:19001' is therefore not allowed access.
makeRequest @ rpc.js:196
As you can see it requesting port 8082 in the XMLHttpRequest, but the server is supposed to be running on port 8081 but is actually on port 8082. The above snippet is a bit confusing, I know :-)
Full request headers from Chrome for create_session:
General:
Request URL:http://localhost:8082/create_session
Request Method:POST
Status Code:200 OK
Remote Address:[::1]:8082
Referrer Policy:no-referrer-when-downgrade
Response Headers:
Access-Control-Allow-Origin:http://localhost:8081
Cache-Control:no-cache
Connection:Close
Content-Length:12
Content-Type:application/json
Date:Fri, 07 Jul 2017 10:42:09 GMT
Server:GCDWebServer
Request Headers:
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:52
Content-Type:text/plain;charset=UTF-8
Host:localhost:8082
Origin:http://localhost:19001
Referer:http://localhost:19001/debuggerWorker.js
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Why is this issue closed? It seems like many are still encountering this problem.
I run into this when starting up an app with remote debugging on a device through Bluetooth State Restoration, which makes it impossible to debug Bluetooth functionality in our case.
I am developing with react-native and I've had this problem for a while
I just fixed this by running
react-native install realm
(I used yarn before)
and
react-native link realm
I am also facing this problem in my ios simulator and can not find solution anywhere. Can someone help me please?
Please file a new issue rather than commenting on an issue that's been closed for 18 months. In your new issue, be sure to include all of the information that's requested in the new issue template.