Skip to content

Error when importing #457

Open
Open
@rodrigodiasf1984

Description

@rodrigodiasf1984
  • Asked question in discussions
  • Tried the troubleshooting Wiki
  • Followed the migration Wiki

Describe the bug
Hi guys I'm getting this error when import the GOOGLE_MAPS_APIKEY from '@env'
I've followed the official documentation, an previous issue and this tutorial, sorry but I don't know what I'm missing.

To Reproduce
Steps to reproduce the behavior:

  1. follow the official readme and this tutorial: https://dev.to/bhatvikrant/how-to-add-environment-variables-in-a-react-native-project-with-ts-2ne5
  2. create the variable on .env file => GOOGLE_MAPS_APIKEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  3. Go to the TSX file and import { GOOGLE_MAPS_APIKEY } from '@env';
  4. See error => Unable to resolve path to module '@env'.eslintimport/no-unresolved

Expected behavior
import the env var without error

Screenshots
image
image
Desktop (please complete the following information):

  • OS: Ventura
  • Browser Arc, Brave
  • Version 13.4

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Babel-config:

module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'nativewind/babel',
'react-native-reanimated/plugin',
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env',
allowUndefined: false,
},
],
],
};

env.d.ts

declare module '@env' {
export const GOOGLE_MAPS_APIKEY: string;
}

package json:

"dependencies": {
"@aws-amplify/api": "^5.4.4",
"@gorhom/bottom-sheet": "^4.4.5",
"@hookform/resolvers": "^2.9.10",
"@notifee/react-native": "^7.8.0",
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-community/datetimepicker": "^6.7.5",
"@react-native-community/netinfo": "^9.3.7",
"@react-native-firebase/app": "^14.11.0",
"@react-native-firebase/messaging": "^14.11.0",
"@react-native-masked-view/masked-view": "0.2.8",
"@react-navigation/native": "^6.0.13",
"@react-navigation/native-stack": "^6.9.1",
"@react-navigation/stack": "^6.3.4",
"@shopify/flash-list": "^1.4.2",
"aws-amplify": "^5.0.14",
"clsx": "^1.2.1",
"date-fns": "^2.29.3",
"lottie-react-native": "^5.1.6",
"nativewind": "^2.0.11",
"phosphor-react-native": "^1.1.2",
"react": "18.1.0",
"react-hook-form": "^7.39.4",
"react-native": "0.70.6",
"react-native-actions-sheet": "^0.8.29",
"react-native-background-fetch": "4.1.5",
"react-native-background-geolocation": "4.10.1",
"react-native-biometrics": "^3.0.1",
"react-native-confirmation-code-field": "^7.3.1",
"react-native-contacts": "^7.0.5",
"react-native-device-info": "^10.4.0",
"react-native-dotenv": "^3.4.9",
"react-native-dropdown-picker": "^5.4.6",
"react-native-flash-message": "^0.4.0",
"react-native-floating-label-input": "^1.4.2",
"react-native-gesture-handler": "~2.8.0",
"react-native-google-places-autocomplete": "^2.5.1",
"react-native-image-crop-picker": "^0.37.3",
"react-native-iphone-x-helper": "^1.3.1",
"react-native-maps": "^1.3.2",
"react-native-modal-datetime-picker": "^14.0.1",
"react-native-open-maps": "^0.4.0",
"react-native-permissions": "^3.6.1",
"react-native-phone-number-input": "^2.1.0",
"react-native-ratings": "^8.1.0",
"react-native-reanimated": "^2.14.4",
"react-native-responsive-screen": "^1.4.2",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-splash-screen": "^3.3.0",
"react-native-svg": "^13.9.0",
"react-native-svg-transformer": "^1.0.0",
"react-native-swipe-gestures": "^1.0.5",
"react-native-swipe-list-view": "^3.2.9",
"react-native-tooltip-2": "^0.1.3",
"react-native-version-check": "^3.4.7",
"react-native-webview": "^13.2.3",
"redux-persist": "^6.0.0",
"rn-swipe-button": "^1.3.8",
"tailwindcss": "3.3.2",
"yup": "^0.32.11",
"zustand": "^4.3.6"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@testing-library/jest-native": "^5.4.1",
"@testing-library/react-native": "^11.5.1",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^29.4.0",
"@types/react": "^17.0.43",
"@types/react-native": "^0.70.11",
"@types/react-native-dotenv": "^0.2.0",
"@types/react-native-version-check": "^3.4.5",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"babel-plugin-module-resolver": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^39.0.0",
"eslint-import-resolver-babel-module": "^5.3.2",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-native": "^4.0.0",
"jest": "^29.6.4",
"jest-transform-stub": "^2.0.0",
"metro-react-native-babel-preset": "0.72.3",
"prettier": "^3.0.3",
"react-native-clean-project": "^4.0.1",
"react-test-renderer": "^18.2.0",
"typescript": "*"
},
"resolutions": {
"@types/react": "17.0.43",
"@types/react-native": "~0.70.6"
}
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions