react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 Metro crashing on every build with EPERM error

Open TatuUlmanen opened this issue 2 years ago • 7 comments

What were you trying to do?

When running npx react-native run-android, the build process starts normally and spawns Metro bundler into another window. The build processes normally, until the task :react-native-vision-camera:compileDebugKotlin is reached. The build continues, but at this point Metro crashes with the error message below:

C:\Users\myname\myapp\app\node_modules\metro-hermes-compiler\src\emhermesc.js:77
          throw ex;
          ^

Error: EPERM: operation not permitted, lstat 'C:\Users\myname\myapp\app\node_modules\react-native-vision-camera\android\build\intermediates\cxx\Debug\3e183j45\obj\armeabi-v7a\libVisionCamera.so.tmp22a6dbd'
Emitted 'error' event on NodeWatcher instance at:
    at C:\Users\myname\myapp\app\node_modules\metro\node_modules\jest-haste-map\build\watchers\NodeWatcher.js:275:14
    at FSReqCallback.oncomplete (node:fs:198:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'C:\\Users\\tatuu\\jemma\\app\\node_modules\\react-native-vision-camera\\android\\build\\intermediates\\cxx\\Debug\\3e183j45\\obj\\armeabi-v7a\\libVisionCamera.so.tmp22a6dbd'
}

From what I understand, Metro is watching some temporary build files in the react-native-vision-camera build folder, and when these are cleaned up, Metro crashes with a "operation not permitted" error.

I didn't find any other issues regarding this problem, even though this is the third machine this happens in.

Is this a react-native-vision-camera problem or a Metro configuration issue? How can I run the build process in a way that doesn't trigger the EPERM error in Metro?

Reproduceable Code

No response

What happened instead?

Metro crashes.

Relevant log output

No response

Device

Android emulator

VisionCamera Version

2.13.2

Additional information

TatuUlmanen avatar May 13 '22 17:05 TatuUlmanen

I hit the same issue, but my problem is not related with the package react-native-vision-camera because I dont use. I dont know what's the root cause, please help!

Zero-Xiong avatar Jul 04 '22 01:07 Zero-Xiong

any solution?

chai00xxdd avatar Jul 15 '22 17:07 chai00xxdd

The only solution I found for now is to just relaunch Metro after this error happens. Pretty annoying but kinda works.

Martinocom avatar Jul 19 '22 08:07 Martinocom

I am having this issue as well but the error mentions 'C:\Users\myname\myapp\app\node_modules\react-native-reanimated\...

I tried everything and I can't get metro not to crash.

reznik99 avatar Sep 05 '22 13:09 reznik99

I am facing this same issue, Not finding any proper solution!

Anyone found solution for this?

sahibprashant avatar Sep 09 '22 07:09 sahibprashant

Solution that worked for me:

1 - Build first: npx react-native run-android This will crash with the same error but that's ok.

2 - Run metro separately: npx react-native start or npm start

This works for me (live reload etc..)

I think the issue is metro starts watching files while the npx react-native run-android is still building/accessing files, and the two interfere with each other.

reznik99 avatar Sep 09 '22 22:09 reznik99

Best solution for now is to run (not really best but at least you won't have to run metro fast after a successful build) : adb reverse tcp:8081 tcp:8081 tcp:8081

So you can now build the app once and you don't need to run it again to connect to the metro. You can start metro later and app will connect to it.

mhackeras avatar Sep 14 '22 08:09 mhackeras

I'm experiencing the same issue with vision camera version 2.15.4

Meijer-A avatar Feb 02 '23 11:02 Meijer-A

  • same error
RuntimeError: abort(Error: EPERM: operation not permitted, lstat 'E:\Workspace\xxx\example\android\app\build\intermediates\cxx\Debug\6n1z393a\obj\arm64-v8a\libappmodules.so.tmp05deaa0'). Build with -s ASSERTIONS=1 for more info.
    at process.abort (E:\xxx\rn_addtoapp_bridge\example\node_modules\metro-hermes-compiler\src\emhermesc.js:402:15)
    at process.emit (node:events:520:28)
    at processEmit [as emit] (E:\Workspace\xxx\example\node_modules\signal-exit\index.js:199:34)
    at emit (node:internal/process/promises:133:20)
    at processPromiseRejections (node:internal/process/promises:260:27)
    at processTicksAndRejections (node:internal/process/task_queues:97:32)
error Command failed with exit code 1.

krmao avatar Apr 16 '23 03:04 krmao

  • same error
RuntimeError: abort(Error: EPERM: operation not permitted, lstat 'E:\Workspace\xxx\example\android\app\build\intermediates\cxx\Debug\6n1z393a\obj\arm64-v8a\libappmodules.so.tmp05deaa0'). Build with -s ASSERTIONS=1 for more info.
    at process.abort (E:\xxx\rn_addtoapp_bridge\example\node_modules\metro-hermes-compiler\src\emhermesc.js:402:15)
    at process.emit (node:events:520:28)
    at processEmit [as emit] (E:\Workspace\xxx\example\node_modules\signal-exit\index.js:199:34)
    at emit (node:internal/process/promises:133:20)
    at processPromiseRejections (node:internal/process/promises:260:27)
    at processTicksAndRejections (node:internal/process/task_queues:97:32)
error Command failed with exit code 1.

already fix the error

metro.config.js

// noinspection JSUnresolvedFunction,JSCheckFunctionSignatures,JSUnusedGlobalSymbols,NpmUsedModulesInstalled

const path = require('path');
const escape = require('escape-string-regexp');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const pak = require('../package.json');
const root = path.resolve(__dirname, '..');
const modules = Object.keys({ ...pak.peerDependencies });

const originBlackListRE = exclusionList(modules.map((m) => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)));

//region for widows RuntimeError: abort(Error: EPERM: operation not permitted, lstat 'E:\Workspace\xxx\example\android\app\build\intermediates\cxx\Debug\6n1z393a\obj\arm64-v8a\libappmodules.so.tmp05deaa0'). Build with -s ASSERTIONS=1 for more info.
// https://stackoverflow.com/a/9213411/4348530
// https://github.com/mrousavy/react-native-vision-camera/issues/1047#issuecomment-1510030983
// https://github.com/expo/expo-cli/issues/2021#issuecomment-1239989633
const extraBlackListRE = new RegExp("(.*\\android\\.*|.*__fixtures__\\.*|node_modules\\\\react\\\\dist\\\\.*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*__tests__\\.*)$");
const finalBlackListRE = new RegExp("(" + originBlackListRE.source + ")|(" + extraBlackListRE.source + ")")
console.log("metro.config.js originBlackListRE=", originBlackListRE)
console.log("metro.config.js extraBlackListRE=", extraBlackListRE)
console.log("metro.config.js finalBlackListRE=", finalBlackListRE)
// originBlackListRE /(^E:\\Workspace\\rn_addtoapp_bridge\\node_modules\\react\\.*$|^E:\\Workspace\\rn_addtoapp_bridge\\node_modules\\react-native\\.*$|\\__tests__\\.*)$/
// extraBlackListRE /(.*\android\.*|.*\__fixtures__\.*|node_modules[\\]react[\\]dist[\\].*|website\node_modules\.*|heapCapture\bundle.js|.*\__tests__\.*)$/
// finalBlackListRE /((^E:\\Workspace\\rn_addtoapp_bridge\\node_modules\\react\\.*$|^E:\\Workspace\\rn_addtoapp_bridge\\node_modules\\react-native\\.*$|\\__tests__\\.*)$)|((.*\android\.*|.*\__fixtures__\.*|node_modules[\\]react[\\]dist[\\].*|website\node_modules\.*|heapCapture\bundle.js|.*\__tests__\.*)$)/
// exit();
//endregion

const metroConfig = {
  projectRoot: __dirname,
  watchFolders: [root],

  // We need to make sure that only one version is loaded for peerDependencies
  // So we block them at the root, and alias them to the versions in example's node_modules
  resolver: {
    blacklistRE: finalBlackListRE,

krmao avatar Apr 16 '23 04:04 krmao

Same Error have to start metro again after build

Dhiraj-j avatar Jul 12 '23 19:07 Dhiraj-j

The issue remains on version 3.6.4

FelipeACP avatar Oct 25 '23 20:10 FelipeACP