I am doing an online course about React-Native and Firebase but I came across an error.
Here it is : Error: Unable to resolve module fs from Documents/code/ChatApp/node_modules/react-native-dotenv/index.js:
I've seen responses that fs is not available on react-native, is that true ?
Why install a package so that in the end it can't be used?
thank you in advance for your answers
CodePudding user response:
No, fs is not available in React Native. You can use the react-native-fs package instead.
https://github.com/itinance/react-native-fs
CodePudding user response:
That online course might be referring to old version of react-native-dotenv
. To make it work with the new version, make these minor changes to your code as explained in this wiki. No need to install fs
.
- If you have a code like this
import { API_URL, API_TOKEN } from 'react-native-dotenv';
change it to
import { API_URL, API_TOKEN } from '@env';
- Make sure
module:react-native-dotenv
is present inbabel.config.js
file. Example -
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
plugins: [
"module:react-native-dotenv",
...
]
};