Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo throwing fs not found error. #408

Closed
Haseebshah936 opened this issue Jan 14, 2023 · 17 comments · Fixed by #417
Closed

Expo throwing fs not found error. #408

Haseebshah936 opened this issue Jan 14, 2023 · 17 comments · Fixed by #417

Comments

@Haseebshah936
Copy link

Error Statement:

The package at "node_modules/react-native-dotenv/index.js" attempted to import the Node standard library module "fs".
It failed because the native React runtime does not include the Node standard library.

Balblel.config

module.exports = function (api) {
  api.cache(false);
  return {
    presets: ["babel-preset-expo"],
    env: {
      production: {
        plugins: [
          ["react-native-paper/babel"],
          [
            "module:react-native-dotenv",
            {
              moduleName: "react-native-dotenv",
              verbose: true,
            },
          ],
        ],
      },
    },
  };
};

Environment:

Expo sdk ~47.0.12
React native 0.70.5
React 18.1.0

@goatandsheep goatandsheep transferred this issue from goatandsheep/react-native-dotenv-expo-test Feb 5, 2023
@github-actions
Copy link

github-actions bot commented Feb 5, 2023

Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/408

@goatandsheep
Copy link
Owner

Hi @Haseebshah936 I've transferred the ticket here from the expo test repo. Can you please verify that you have installed react-native-dotenv as a devdependency ?

@Haseebshah936
Copy link
Author

@goatandsheep yes I installed it as a dependency. But for now I am not using it. Still if you need any help regrading testing I will be happy to help you ☺️.

@goatandsheep
Copy link
Owner

Thank you for the help! To be clear was it installed as a regular dependency or devdependency? It needs to be installed as a devdependency

@patrickpistor
Copy link

@goatandsheep Running into this issue as well with it installed as a dev dependency. Latest version of expo SDK

@goatandsheep
Copy link
Owner

@patrickpistor are you importing react-native-dotenv in your app? Expo will bundle all libraries that are imported whether or not they are installed as devDependency. Also if you are, can you verify that in your Babel that you have set your module name in your babel.config.js to "react-native-dotenv" so it is replaced by Babel with the env object?

@goatandsheep
Copy link
Owner

@patrickpistor I stalked your profile and noticed this package.json has react-native-dotenv in the dependencies array not devDependencies https://github.com/Photure/PhotureEthGlobal/blob/master/package.json

@software-trizzey
Copy link

Hey there, I also encountered this error today in a fresh project while following the README.md.

My setup:

Imported it:

// index.ts

import {
	REACT_NATIVE_SUPABASE_URL,
	REACT_NATIVE_SUPABASE_ANON_KEY,
} from "react-native-dotenv";

My types file:

// types/env.ds.tsx

declare module "react-native-dotenv" {
	export const REACT_NATIVE_SUPABASE_URL: string;
	export const REACT_NATIVE_SUPABASE_ANON_KEY: string;
}

const supabaseUrl = REACT_NATIVE_SUPABASE_URL;
const supabaseAnonKey = REACT_NATIVE_SUPABASE_ANON_KEY;

My babel.config.js:

module.exports = function (api) {
	api.cache(true);
	return {
		presets: ["babel-preset-expo"],
		plugins: [
			[
				"module:react-native-dotenv",
				{
					moduleName: "react-native-dotenv",
					path: ".env",
				},
			],
		],
	};
};

Error encountered:

iOS Bundling failed 294ms
The package at "node_modules/react-native-dotenv/index.js" attempted to import the Node standard library module "fs".
It failed because the native React runtime does not include the Node standard library.

@goatandsheep
Copy link
Owner

goatandsheep commented Feb 8, 2023

Hi @IM-Deane can you please verify in your package.json that react-native-dotenv is a devDependency NOT a dependency? Otherwise setup looks fine. I would recommend changing to api.cache(false)

@patrickpistor
Copy link

patrickpistor commented Feb 8, 2023

@patrickpistor I stalked your profile and noticed this package.json has react-native-dotenv in the dependencies array not devDependencies https://github.com/Photure/PhotureEthGlobal/blob/master/package.json

@goatandsheep that project is dated, this is the one I am using the correct package in the correct place https://github.com/patrickpistor/mixer.

The error seems to be around fs installing correctly at this point.

@patrickpistor
Copy link

I have an open bounty for $45 on Replit if anyone can figure this out: https://replit.com/bounties/@patrickpistor1/create-a-react-nativ

@goatandsheep
Copy link
Owner

I didn't see the error regarding fs
https://www.loom.com/share/20b80aa6ab1b4bfb922ce097a187937b
https://github.com/goatandsheep/mixer-bounty

@goatandsheep
Copy link
Owner

also i have a second expo example here https://github.com/goatandsheep/react-native-dotenv-expo-test

@patrickpistor
Copy link

Thanks @goatandsheep That repo that you made worked. I can give you the bounty if you apply on Replit

@goatandsheep
Copy link
Owner

I've applied! :)

@patrickpistor
Copy link

@goatandsheep I accepted you, just submit something and I'll approve it!

@goatandsheep
Copy link
Owner

thank you! I uploaded a replit :)
I realized you removed the yarn upgrades, so maybe it was the esModuleInterop. I will add that to the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants