Logging Current Directory/Filename in React Native - react-native

I was wondering if there is a way to log the current filename or directory in React Native. Similar to how NodeJS does it with __filename and __dirname.

No, it's not possible since all the source code gets bundled together into one big file, and then a source map is provided so that you can debug it in the original structure.
You can see that by calling this code snippet somewhere in your code:
console.log(new Error().stack);
In a regular javascript you would get the entire trace with files and line numbers, but in react-native you get somthing like:
Error
at Login (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:83009:9)
at instantiate (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:5712:18)
at new Login (eval at proxyClass (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:5730:16), <anonymous>:4:17)
at ReactCompositeComponentWrapper._constructComponentWithoutOwner (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22051:19)
at ReactCompositeComponentWrapper._constructComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22033:13)
at ReactCompositeComponentWrapper.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:21952:15)
at Object.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:20425:29)
at ReactCompositeComponentWrapper.performInitialMount (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22134:28)
at ReactCompositeComponentWrapper.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22015:13)
at Object.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:20425:29)"
which shows you the real files are gone.

Related

Vue: Showing that the function does not exist when I have defined it the relevant store

I am currently working on a simple app to store workout routines in Nuxt 3 and Appwrite. The link to the source code is here.
After logging in and adding in some workouts in the app's UI, whenever I try to call the deleteWorkout function, I get an error in the console saying that the function is not defined, whereas I have clearly defined in the workoutStore. I can't seem to figure out the reason for the same.
The same can be seen in the given screenshot.
Console on clicking the delete button
PS:
Most probably the error should be originating from either /pages/workouts.vue, /components/WorkoutDetails.vue or /stores/workout.js.
I am using Appwrite to manage the back-end of the web app, and the instructions to setup the same can be found in the README.md. (Though I don't think the error I am facing is related to the same.)
In your code the problem is, you declear your deleteWorkout() function outside of the actions block in workout.js file.
Make sure all your functions in the workout store are inside the actions block. Then it will be accessable from the vue component

React-Native Uncaught syntax error: Cannot import statement outside a module

Here is an image of the top lines of a simple(ish) app.js (not using the bluetooth stuff yet - all commented out)
So no biggie as app seems to work regardless, but I'm interested in why I get it and what can be done to remove it.
Some previous questions seem related to the use of something called Jest (no idea what that is - I suppose I should look it up?)
Jest Testing React Native cannot use import statement outside of a module
Putting it here for benefit of others who may come across it.

Getting the following error: Unable to resolve "../assets/icon.png" from "app\assets\screens\WelcomeScreen.js"

When I try to run my app I get the error
Unable to resolve "../assets/icon.png" from "app\assets\screens\WelcomeScreen.js"
Error: Problems validating asset fields in app.json. See https://docs.expo.io/
• Field: icon - cannot access file at './assets/icon.png'.
I created a screens folder and input my homescreen into it as I heard that the majority of the react native community does things that way. Attached is a picture of my filesenter image description here
I think that the image path is off, however I had changed it multiple times and am still getting the same error.
Any help would be appreciated.
try the following: ../icon.png
Cause that's what I can see from your file structure.
If you use visual studio code as dev tool, when you type path cue, correct path will be appeared. so you can avoid to make mistake in path of image.

Persistent React-Native error that goes away with Remote Debugging enabled

I'm building a React-Native app and whenever I run it on my Android emulator, I get this error:
Objects are not valid as a React child (found: object with keys
{$$typeof, type, key, ref, props, _owner, _store}). If you meant to
render a collection of children, use an array instead.
throwOnInvalidObjectType
D:\rn\manager\node_modules\react-native\Libraries\Renderer\ReactNativeRenderer-dev.js:7436:6
Because this error means nothing to me, I decide to enable "Debug JS Remotely" in Chrome to see if I can get an error I understand. But with Debug Remotely enabled, the error goes away.
If I build the project and install the app on a real device, the errors come back.
But I feel like I'm stuck in a catch-22 because if I try to debug, I get no errors, and if I turn off debugging, I get errors.
Is there anyway to get around this?
Thanks!
The error mentions you use an object in your render() method where you shouldn't. Since you did not post any code, here is what you could do:
Keep removing elements from your render() method until you no longer get the error. Once it is gone, start placing code back until you hit the error again. The code causing the error will be or return an object, possibly a typo causing an object to be returned instead of a string for instance.
TL;DR: Stopped using firebase and used react-native-firebase instead
The problem for me wasn't the render method in any of my components or classes. I realized after trying the answer above, I basically removed all my files, and was left with one file. I changed the render method to display text inside one view, but I still got the error.
Then I started removing the modules I was importing inside that file one by one and found that it was the firebase module uninstalled firebase and installed react-native-firebase.

Menu Items are not getting displayed

I implemented WL.OptionsMenu in android environment as specified in Worklight APIs(android/js/mainApp.js). If menu option is clicked, I've given a callback function . Its working fine if the callback resides in the same file. But the implementation of that callback is resided in android/native/common/js/mainApp.js file. Hence, its not showing the menuOptions in android mobile. How to solve this problem?
Edit your question with the contents of mainApp.js
There is no such path, in Worklight, as android/native/common/js/mainApp.js.
Perhaps you mean android/native/assets/www/default/common/js/mainApp.js, but then again, it is exactly the same as android/js/mainApp.js.
The only difference is that android/native/assets/www/default/common/js/mainApp.js is created after you build your application.
There is no reason why it should not work.
Again, edit your question with the contents of mainApp.js and the steps you have taken from creating the project, to running it in your device/emulator.