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

error: Error: Unable to resolve module @env #394

Closed
maoryadin opened this issue Dec 20, 2022 · 14 comments
Closed

error: Error: Unable to resolve module @env #394

maoryadin opened this issue Dec 20, 2022 · 14 comments
Assignees

Comments

@maoryadin
Copy link

No matter what I do, it's just not working.

babel.config.json:

{
    "presets": ["@babel/preset-react","module:metro-react-native-babel-preset"],
    "plugins": [
      ["module:react-native-dotenv", {
        "moduleName": "@env",
        "path": ".env",
        "safe": false,
        "allowUndefined": true
      }]
    ]
}

error:

error: Error: Unable to resolve module @env from /Users/maoryadin/spetz-git/project/src/constants/config.js: @env could not be found within the project or in these directories:
  node_modules
  ../../node_modules
  1 | import {AppColors, AppSizes, AppStyles} from '../theme';
  2 | import {Platform} from 'react-native';
> 3 | import {SERVER_URL, RATING_URL, ENV} from '@env';

I have a .env file that exists.

@github-actions
Copy link

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/394

@goatandsheep
Copy link
Owner

Is the library installed as dev dependency?

@goatandsheep
Copy link
Owner

goatandsheep commented Dec 20, 2022

Also try using Babel.config.js and setting API.cache(false)
You shouldn't need this but if you didn't update your Babel then this is a workaround

@maoryadin
Copy link
Author

Is the library installed as dev dependency?

yes, installed in devDependencies

@maoryadin
Copy link
Author

maoryadin commented Dec 20, 2022

Also try using Babel.config.js and setting API.cache(false) You shouldn't need this but if you didn't update your Babel then this is a workaround

So as you suggested I am now using babel.config.js
I am getting a different errors:

[BABEL]: Cannot find module 'node:fs'

my react-native-dotenv version is 3.4.6 by the way.

@goatandsheep
Copy link
Owner

Can you please show me a test repo? I haven't been able to break it.

@maoryadin
Copy link
Author

Hey, i have successfully succeeded, i think adding import react before has fixes the issue, not sure but its work :)

@abiScript
Copy link

abiScript commented Apr 22, 2023

Hey, i have successfully succeeded, i think adding import react before has fixes the issue, not sure but its work :)

Can confirm that adding the import for the env module before importing anything else worked for me as I had just run into the same issue.

@goatandsheep
Copy link
Owner

Hi tomorrow I will verify and I can update the docs to include this :)

@enzzoperez
Copy link

Hey, i have successfully succeeded, i think adding import react before has fixes the issue, not sure but its work :)

Hi!, Im having the same issue, how is the fix that you used?, I have my react import in first line in my file where Im using the @env import, but doesnt work

@Narayen
Copy link

Narayen commented May 29, 2023

Hi,

I had the same issue, while trying to import through @env. as suggested in the above comments, I tried importing React and it worked for me.

I added the import React from 'react'; at the first line.

@DeeDyPL
Copy link

DeeDyPL commented May 29, 2023

Hi,

I had the same issue, while trying to import through @env. as suggested in the above comments, I tried importing React and it worked for me.

I added the import React from 'react'; at the first line.

Yes, it helped!

@TausifM
Copy link

TausifM commented Dec 13, 2023

Is the library installed as dev dependency?

Yes

@goatandsheep
Copy link
Owner

Where should people import react?

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

No branches or pull requests

7 participants