expo: axios Problem sending console.log - console.error There was a problem sending log messages
hello
I’m working with Expo React native, I’m trying to send request to an api and console log the response it’s working perfectly with fetch but using axios
axios.get('https://rallycoding.herokuapp.com/api/music_albums') .then((response) => console.log(response));
i get this
here is my package.json
{ "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "eject": "expo eject" }, "dependencies": { "axios": "^0.14.0", "expo": "^32.0.0", "react": "16.5.0", "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz" }, "devDependencies": { "babel-preset-expo": "^5.0.0", "eslint-config-rallycoding": "^3.2.0" }, "private": true }
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 16 (4 by maintainers)
Ok everyone, i just started using react native this year, but I have decided to help everyone out because i also had this stupid problem, and figured it out on my own, and decided to come back to post this. This is due to the fact that the React native console logger CANNOT parse the JSON object coming from Axios. I can guarantee that anyone who is having this error is not PARSING the JSON object before logging it to the console.
CODE THAT WILL GIVE THIS ERROR: Axios.post(URL).then(function (response) { console.log("POST RESPONSE: " , response); }
CODE THAT FIXES THIS ERROR: Axios.post(URL).then(function (response) { console.log("POST RESPONSE: " , JSON.stringify(response)); }
For everyone having this issue, it’s because you’re trying to console log too much, as suggested above the only solution I found was to log the specific data you need i.e
response.data.selected_key,outside of needing to see everything coming in, it kind of makes sense.
Any solution ? I got same fucking issue
The result itself is huge in size and axios would not be able to send it to logging Either you can stringify the result or console.log(res.data);
This would solve the issue.
Either use
response.dataorJSON.stringify(response). It’s because in response there are other informations like “status”, “headers”, “config”, “request”, “responseURL”. It makes it a big enough JSON obj to console log i guess. This is what I figured out to solve this problem.@kouraf Hello, kouraf. I’ve been struggling with that problem for a few days, but I’ve not solved. If you solved this problem, could you help me to get through this situation?
@kouraf this isn’t an issue with expo - I believe this is either a babel issue or a react native issue, as it began happening with me since upgrading to babel 7. Not sure if you realized, but despite it being a red screen, you can just dismiss it and keep working.
Unfortunately the only way you can avoid this is to avoid console logging complex objects - it’s annoying for me too (I use axios) but I haven’t found any workarounds besides that 😕