React Native—react-native-dotenv error: api.addExternalDependency is not a function

I am using Expo (version: ~47.0.12) with React Native (version: 0.70.5), and I am unable to use the react-native-dotenv npm package. I have followed many tutorials, and they all result in this same error message:

./node_modules/expo/AppEntry.js
TypeError: [BABEL] /Users/jessicagallagher/projects/sfl/sfl-mobile/node_modules/expo/AppEntry.js: api.addExternalDependency is not a function (While processing: "/Users/jessicagallagher/projects/sfl/sfl-mobile/node_modules/react-native-dotenv/index.js")

The tutorials that I have used are basically blogs stating the same information from the docs.

This is my babel.config.js file:

module.exports = function(api) {
  api.cache(false);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['module:react-native-dotenv'],
  };
};

I have also tried this in my babel.config.js file:

"plugins": [
    ["module:react-native-dotenv", {
      "moduleName": "@env",
      "path": ".env",
      "blocklist": null,
      "allowlist": null,
      "safe": false,
      "allowUndefined": true,
    }]
  ]

My .env file is the standard .env:

API_KEY='12345'

Here is my import statement to access the variable:

import { API_KEY } from '@env';

Normally in VS Code, when I start typing import { Something } from ', I will normally get suggestions from packages I have installed. That does not happen here when using @env—the suggestion does, however, show up when I import from 'react-native-dotenv', but I still get that same error message.

I've read a ton of GitHub issues and am just spinning my wheels at this point.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation