skip to Main Content

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:

enter image description here

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

3

Answers


  1. No, fs is not available in React Native. You can use the react-native-fs package instead.

    https://github.com/itinance/react-native-fs

    Login or Signup to reply.
  2. 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.

    1. 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';
    
    1. Make sure module:react-native-dotenv is present in babel.config.js file. Example –
    module.exports = {
      presets: ["module:metro-react-native-babel-preset"],
      plugins: [
        "module:react-native-dotenv",
        ...
      ]
    };
    
    Login or Signup to reply.
  3. react-native-dotenv author here: reinstall the library as a dev dependency

    npm i -D react-native-dotenv
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search