Skip to content

Package initalization Error #512

Open
@RameshTigeen

Description

@RameshTigeen

Description
When running the React Native project, an error occurs related to the path module in react-native-dotenv. The error message states that the path module could not be found within the project or in the directories like node_modules. This results in the build process failing with a module resolution error.

Steps to Reproduce
Create a new React Native project or use an existing one.
Install and configure react-native-dotenv to load environment variables.
Attempt to run the app with the command npm run android (or npx react-native run-android).
The error message is thrown, and the build process fails.
Expected Behavior
The project should build successfully, and the environment variables should be loaded properly using react-native-dotenv.

Actual Behavior
The build fails with the following error message:

 Error: Unable to resolve module path from D:\React Native\devutilsapp\node_modules\react-native-dotenv\index.js: path could not be found within the project or in these directories:
  node_modules
  1 | const fs = require('fs')
> 2 | const path = require('path')
    |                       ^
  3 | const dotenv = require('dotenv')
  4 |
  5 | function parseDotenvFile(path, verbose = false) {
    at ModuleResolver.resolveDependency (D:\React Native\devutilsapp\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:148:15)
    at DependencyGraph.resolveDependency (D:\React Native\devutilsapp\node_modules\metro\src\node-haste\DependencyGraph.js:235:43)
    at D:\React Native\devutilsapp\node_modules\metro\src\lib\transformHelpers.js:160:21
    at resolveDependencies (D:\React Native\devutilsapp\node_modules\metro\src\DeltaBundler\buildSubgraph.js:42:25)
    at visit (D:\React Native\devutilsapp\node_modules\metro\src\DeltaBundler\buildSubgraph.js:83:30)
    at async Promise.all (index 2)
    at async visit (D:\React Native\devutilsapp\node_modules\metro\src\DeltaBundler\buildSubgraph.js:92:5)
    at async Promise.all (index 2)
    at async visit (D:\React Native\devutilsapp\node_modules\metro\src\DeltaBundler\buildSubgraph.js:92:5)
    at async Promise.all (index 0)

Environment
OS: Windows 10
React Native Version: 0.75.1
Node Version: v21.7.3
Package Manager: npm
react-native-dotenv Version: Latest

Additional Information
The error might be related to the use of core Node.js modules (like path) in React Native, which doesn't natively support some of these modules.
Possible solution could involve checking for a compatibility issue between react-native-dotenv and the current React Native version, or ensuring the appropriate polyfills are used for Node.js core modules.

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