Error while Metro is running: metro-hermes-compiler\src\emhermesc.js:77

Viewed 4748

I start metro by yarn start. Another terminal I run yarn android. While the app is installing, below error comes on metro terminal and metro stops executing:

C:\Users\SAMSUNG\Desktop\ReactNativeProjects\MyApp\node_modules\metro-hermes-compiler\src\emhermesc.js:77
          throw ex;
          ^

Error: EPERM: operation not permitted, lstat 'C:\Users\SAMSUNG\Desktop\ReactNativeProjects\MyApp\node_modules\react-native-gesture-handler\android\build\kotlin\compileDebugKotlin\caches-jvm'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (C:\Users\SAMSUNG\Desktop\ReactNativeProjects\MyApp\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:168:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'C:\\Users\\SAMSUNG\\Desktop\\ReactNativeProjects\\MyApp\\node_modules\\react-native-gesture-handler\\android\\build\\kotlin\\compileDebugKotlin\\caches-jvm'
}

I again launch metro by yarn start while app is being built. And when the app build finishes, following crash occurs:

 BUNDLE  ./index.js

 ERROR  TypeError: undefined is not an object (evaluating 'InnerNativeModule.installCoreFunctions')
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the
error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the
error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

I didn't understand anything. These problems occured while I was trying to add library @react-navigation/drawer with its prerequisites: yarn add react-native-gesture-handler react-native-reanimated

2 Answers

Had the same problem on Windows 10. Changing the node_watcher.js fixed the issue for me. I changed the function isIgnorableFileError to work for error === null and used this function in the NodeWatcher class. The changes are far from perfect, but now it works.

First guess - an permission issue when NodeWatcher and the build access a file at the same time.

Here is the result of yarn patch-package sane

diff --git a/node_modules/sane/src/node_watcher.js b/node_modules/sane/src/node_watcher.js

index ce90e4e..51b5e9a 100644

--- a/node_modules/sane/src/node_watcher.js

+++ b/node_modules/sane/src/node_watcher.js

@@ -287,7 +287,7 @@ module.exports = class NodeWatcher extends EventEmitter {

     fs.lstat(

       fullPath,

       function(error, stat) {

-        if (error && error.code !== 'ENOENT') {

+        if (!isIgnorableFileError(error)) {

           this.emit('error', error);

         } else if (!error && stat.isDirectory()) {

           // win32 emits usless change events on dirs.

@@ -304,7 +304,7 @@ module.exports = class NodeWatcher extends EventEmitter {

               this.emitEvent(ADD_EVENT, relativePath, stat);

             }

           }

-        } else {

+        } else if (!error) {

           let registered = this.registered(fullPath);

           if (error && error.code === 'ENOENT') {

             this.unregister(fullPath);

@@ -390,9 +390,14 @@ module.exports = class NodeWatcher extends EventEmitter {

  * @private

  */

 function isIgnorableFileError(error) {

+  if (error !== null)

+  {

+    console.log(error + " " + platform)

+  }

   return (

+    error === null ||

     error.code === 'ENOENT' ||

     // Workaround Windows node issue #4337.

-    (error.code === 'EPERM' && platform === 'win32')

+    (error.code === 'EPERM')

   );

 }

I got the this exact problem and I managed to fixed it by cleaning previous builds("android/app/build" delete the whole build folder). Just incase also delete "node_modules" and do npm i or yarn. Finally, run the project yarn start --reset-cache then yarn android.

Related