React Native - Constant errors like "Error: EPERM: operation not permitted, lstat ..."

Viewed 7923

I am fairly new to React Native, and it appears my app is crashing prior to executing my primary app code, but I cannot figure out where. In VSCode, I see the following in my Output:

Error: EPERM: operation not permitted, lstat 'c:\Dev\myapp\android\app\build\generated\not_namespaced_r_class_sources\debug\r\com\bumptech\glide\integration\okhttp' Emitted 'error' event on NodeWatcher instance at: at NodeWatcher. (c:\Dev\myapp\node_modules\sane\src\node_watcher.js:291:16) at FSReqCallback.oncomplete (fs.js:176:21) { errno: -4048, code: 'EPERM', syscall: 'lstat', path: 'c:\Dev\myapp\android\app\build\generated\not_namespaced_r_class_sources\debug\r\com\bumptech\glide\integration\okhttp'

I'm trying to figure out how to determine where this is coming from, and how to debug errors like this in the future.

6 Answers

I also got same Error while working with react-native on windows.

I am not sure the root cause of this error but following the steps below helps me to solve the problem.

  1. On Android Studio go to File>invalidate Caches/Restart*

  2. Terminate local react native server

  3. Then Run npx react-native start --reset-cache and npm run android

Following these steps helped me most of the time. If there are better ways to solve this I am very Happy to know as well.

Had a similar problem on Windows 10. Seems that the node watcher modules of sane and metro throw an error if other programs access a file when they try to check for changes. Other programs may be a virus scanner, git, java, gcc, etc. At the end I patched the NodeWatcher.js and node_watcher.js files to ignore the error. Using yarn patch-package package-name stored the necessary changes in my project. Example changes in NodeWatcher.js:

  processChange(dir, event, file) {
const fullPath = path.join(dir, file);
const relativePath = path.join(path.relative(this.root, dir), file);
// Use isIgnorableFileError to ignore EPERM errors on Windows machines
// when watching the file system. E.g. http://bitstopixels.blogspot.com/2017/04/react-native-windows-10-eperm-operation.html
fs.lstat(fullPath, (error, stat) => {
  if (!isIgnorableFileError(error)) {
    this.emit('error', error);
  } else if (!error && stat.isDirectory()) {
    // win32 emits usless change events on dirs.
    if (event !== 'change') {
      this.watchdir(fullPath);

      if (
        common.isFileIncluded(
          this.globs,
          this.dot,
          this.doIgnore,
          relativePath
        )
      ) {
        this.emitEvent(ADD_EVENT, relativePath, stat);
      }
    }
  } else if (!error) {
    const registered = this.registered(fullPath);

    if (error && error.code === 'ENOENT') {
      this.unregister(fullPath);
      this.stopWatching(fullPath);
      this.unregisterDir(fullPath);

      if (registered) {
        this.emitEvent(DELETE_EVENT, relativePath);
      }
    } else if (registered) {
      this.emitEvent(CHANGE_EVENT, relativePath, stat);
    } else {
      if (this.register(fullPath)) {
        this.emitEvent(ADD_EVENT, relativePath, stat);
      }
    }
  }
});

and

function isIgnorableFileError(error) {
  return (
    error === null || // Allow usage for no error too
    error.code === 'ENOENT' || // Workaround Windows node issue #4337.
    (error.code === 'EPERM' && platform === 'win32')
  );
}

so that I can use the isIgnorableFileError function in processChange.

I'm not sure if this fixes all issues, but for me it worked. Now I can build and run my app without metro crashes.

Go to the Android folder using

cd android && ./gradlew app:installDebug

Go back to the main folder by

cd ..

Now run npx react-native run-android

Ended up reverting back after a massive upgrade and then upgraded a bit more slowly. I've eliminated these errors thus far, but I haven't completed the upgrade. Will post back if I find the culprit.

I got this error many time while working with react native.

Follow these simple steps to get out of this error:

  1. On Android Studio, Go to File > invalidate Caches..(Restart)

  2. Terminate server you have started by npm start

  3. Run following commands respectively.

npx react-native start --reset-cache

npx react-native run-android

Mostly my error get resolved by doing this.

Related