Closed pdaniloais closed 7 years ago
Hello, I have exactly the same issue. May I know how you solved it? Thanks a lot!
Hey i've got the same issue, can you give us more info on how you fixed it?
I had the same issue until i added react-native-dotenv
to my .babelrc
presets. Hope this can help.
I have the same issue with react-native 0.50.4. Any ideas?
@clementino36 How to add it to presets?
@dlucidone here's my .babelrc
{
"presets": [
"babel-preset-expo",
"react-native-stage-0",
"react-native-dotenv"
]
}
For me it was an issue with having a space in my absolute file path
If you do need to do this you may need to run
rm -rf ios/build/ModuleCache/*
so that your builds dont run off of the old file path
If anyone runs into this on RN 0.57 or greater, you may need to adjust the .babelrc
to be
{
"presets": ["module:metro-react-native-babel-preset", "module:react-native-dotenv"]
}
My .babelrc is
{ "presets": [ "module:metro-react-native-babel-preset", "modle:react-native-dotenv" ] }
But I still get this issue. Would there be an alternate solution?
I'm using node 8.9.1 and npm 4.6.1
@jmasaki24 hopefully wasn't because of the typo there :)
changed babel.rc
to babel.config.js
worked for me:
this is with RN 57 and babel 7. you'll also need to ensure you've got all the correct babel 7 dependencies installed via npm, and ensure you've got the lastest version of react-native-dotenv
module.exports = function (api) {
api.cache(true)
return {
"presets": ["module:metro-react-native-babel-preset", "module:react-native-dotenv"]
};
}
@jamesmcn1 I don't even know man, I just do everything from scratch again and it works....
Tried to solve as @jamesmcn1 said, and also reset the simulator and it works
@raymanhjn and @jamesmcn1 I am also experiencing this issue on ios
I have babel.config.js
correctly configured and the app works fine on my Ubuntu 18 OS running android, but does not work on Mac OS High Sierra and the Iphone 10 simulator (even after resetting the simulator and deleting node_modules)
I am using react-native-dotenv v 2.0
the error message says Cannot find module react-native-dotenv from 'Users/fabriziobertoglio/Documents/sourcecode/native/surfnative' (null)
react native 0.57.8
reading the metro logs took me to this other error jeste-haste-map Cannot find module './blacklist'
Thanks for the help
I've just performed a clean install of React Native 0.60.5, Babel 7.6.0 and react-native-dotenv 0.2.0,
my babel.config.js file:
module.exports = {
presets: ['module:metro-react-native-babel-preset','module:react-native-dotenv']
};
And I got the same error:
Unable to resolve the module 'path' from /node_modules/react-native-dotenv/index.js: Module 'path' does not exist in the Haste module map
Anyone found the solution yet?
i run into this in react-native 0.61.2
This worked for me:
npm i --save-dev react-native-dotenv
npm i --save-dev metro-react-native-babel-preset
create .babelrc
{
"presets": ["module:metro-react-native-babel-preset", "module:react-native-dotenv"]
}
I was still seeing the error at this point then ran:
expo start -c
changed
babel.rc
tobabel.config.js
worked for me:this is with RN 57 and babel 7. you'll also need to ensure you've got all the correct babel 7 dependencies installed via npm, and ensure you've got the lastest version of
react-native-dotenv
module.exports = function (api) { api.cache(true) return { "presets": ["module:metro-react-native-babel-preset", "module:react-native-dotenv"] }; }
this babel.config.js file resolved my issue along with yarn start --reset-cache
This worked to me:
Installed these packages:
$ yarn add -D metro-react-native-babel-preset
$ yarn add -D react-native-dotenv
.babelrc
{
"presets": [
"module:metro-react-native-babel-preset",
"module:react-native-dotenv"
]
}
Created a .env
file in the root of the project:
API_HOST=<http-url>
After that file .env
could be loaded in the code:
import { API_HOST } from 'react-native-dotenv';
console.log(API_HOST);
After performing these changes, make sure you clear cache by running npm start -- --reset-cache
.
Adding --reset-cache worked for me I'm using npx so its npx react-native start --reset-cache
I added in my babel.config.js
const plugins = [
// ... some plugins ...
]
module.exports = {
presets: ['module:metro-react-native-babel-preset', 'module:react-native-dotenv'],
plugins: [...plugins],
};
Works fine too for react-native > 0.60
I added react-native-dotenv with
yarn add react-native-dotenv --save-dev
I created a 2e2test.env in the root directory with:
I call react-native-dotenv from my code:
but when I run my app in the iOS simulator, I have the following error:
Ideas ?