I am trying to integrate the latest version of log4js (techically log4js-node but it seems log4js is now used for the latter) into a React Native project. I installed the package using Yarn 1.0.2 and wrote a few lines of code just to test the concept of configuring a logger and seeing some logs. When I tried to start the React Native packager and open the app in my emulator, I got the following exception:
error: bundling failed: Error: Unable to resolve module 'fs' from 'C:\path_to_project\node_modules\log4js\lib\log4js.js': Module 'fs' does not exist in the Haste module map
I looked at the above file and noticed that there is a variable that depends on the fs package. I installed the fs package and tried again, but got this error:
error: bundling failed: Error: While trying to resolve module 'fs' from file 'C:\path_to_project\node_modules\log4js\lib\log4js.js', the package 'C:\path_to_project\node_modules\fs\package.json' was successfully found. However, this package itself specifies a 'main' module field that could not be resolved ('C:\path_to_project\node_modules\fs\index'). Indeed, none of these files exist:
* ‘C:\path_to_project\node_modules\fs\index.js(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)’
* ‘C:\path_to_project\node_modules\fs\index.js\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)’
at ResolutionRequest.resolveDependency (C:\path_to_project\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:103:15)
at DependencyGraph.resolveDependency (C:\path_to_project\node_modules\metro\src\node-haste\DependencyGraph.js:272:4579)
at dependencies.map.relativePath (C:\path_to_project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:376:19)
at Array.map (native)
at resolveDependencies (C:\path_to_project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:374:16)
at C:\path_to_project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:212:33
at Generator.next (<anonymous>)
at step (C:\path_to_project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:297:313)
at C:\path_to_project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:297:473
I am aware that the fs package is not currently in use but if that's the case, how is the log4js package being used? It seems to be regularly updated, looking at its Github repository.
I noticed that when I do install fs, I get the graceful-fs package in my node_modules
folder instead. (but in package.json
I see the fs package, not graceful-fs)
As well as doing the above, I tried cleaning Gradle, installing graceful-fs explicitly and installing react-native-fs but all these things made no difference.