Issue
Ive installed react-native-dotenv in my react-native-project
(non expo) and Im getting this error
error: Error: Unable to resolve module path from C:\XXX\XXX\XXX\node_modules\react-native-dotenv\index.js: path could not be found within the project or in these directories:
node_modules
..\..\..\..\..\node_modules
1 | const {readFileSync, statSync} = require('fs')
> 2 | const path = require('path')
| ^
3 | const dotenv = require('dotenv')
4 |
5 | function parseDotenvFile(path, verbose = false) {
Read up online and people say you need to modify your babel.config
in which I did
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module:react-native-dotenv',
{
envName: 'APP_ENV',
moduleName: '@env',
path: '.env',
},
],
],
};
But it still reproduces the same error and most of these fixes are for expo, Ive never worked with expo and I tried the following
https://stackoverflow.com/a/64227089/5413196
https://github.com/goatandsheep/react-native-dotenv/wiki/Migration-Guide
https://github.com/facebook/react-native/issues/29314
And I am still getting the same error, could someone please advise how to fix ?
Solution
react-native-dotenv
author here: as said in the comment above, Babel config looks great. Make sure to install the lib as a dev dependency.
Answered By - Kemal Ahmed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.