Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

File watcher permissions error on Windows causes crash #2021

Closed
katontech opened this issue Apr 28, 2020 · 38 comments
Closed

File watcher permissions error on Windows causes crash #2021

katontech opened this issue Apr 28, 2020 · 38 comments
Labels
error message improvement needed OS: Windows The issue is occurring on Windows

Comments

@katontech
Copy link

katontech commented Apr 28, 2020

Description

Expo server crashes frequently.
I was reporting that I had the same symptoms as Issue #519, but that was my mistake.

Expected Behavior

The server crashes while running expo start and connecting to the device.

Observed Behavior

events.js:287
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat '<path-to-the-project>\table.xsl.tmp'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (<path-to-the-project>\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:167:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: '<path-to-the-project>\\table.xsl.tmp'
}

I'm not sure what the file "table.xsl.tmp" came from. This file name is shown in the error message of all my projects.
Fortunately, I've found that I can avoid a crash by leaving an empty file with this name in my project root.

Environment

  Expo CLI 3.19.2 environment info:
    System:
      OS: Windows 10 10.0.18363
    Binaries:
      Node: 12.16.2 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.4 - C:\Users\<user-name>\AppData\Roaming\npm\yarn.CMD
      npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  3.6.0.0 AI-192.7142.36.36.6308749
    npmPackages:
      expo: ^37.0.7 => 37.0.7
      react: ~16.9.0 => 16.9.0
      react-native: https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz => 0.61.4

The connection devices are as follows.

  • iPhone 6 (iOS 12.4.5)
  • iOS simulator (iOS 13.3) [iPhone 11, iPad Pro (9.7-inch), ...]
  • Android emulator (Android 10)
@brentvatne
Copy link
Member

also see: oblador/react-native-vector-icons#354

you can try running as administrator as suggested in that issue

@brentvatne brentvatne changed the title Expo server crashes often. File watcher permissions error on Windows causes crash Apr 28, 2020
@brentvatne
Copy link
Member

maybe we can watch EPERM errors and link people to some expo.fyi doc that explains how they can work around this

@katontech
Copy link
Author

I tried expo start in admin console and it crashed with the exact same error message.
As a development user, my account has full permissions on the '<path-to-the-project> \ table.xsl.tmp' file.
Why does expo start try to touch the '<path-to-the-project> \ table.xsl.tmp' file and it fails? :-)

@brentvatne
Copy link
Member

brentvatne commented Apr 29, 2020

as far as i know it does not, seems like something with your machine. feel free to clone the repo and install node_modules and scan for that file everywhere and you won't find it. when in doubt it's generally some weird windows thing

@katontech
Copy link
Author

I found that the new project created by expo init with expo-cli@3.20.0 does not reproduce the symptoms.
So, after deleting the node_modules of the project where the problem occurred and running npm i, the symptom did not reappear in this project. This project was created by expo-cli@3.17.15, so some circumstances may have changed.

Thank you for your cooperation.

@SohailHaqyar
Copy link

Still having the same problem with version 3.20.0

@katontech
Copy link
Author

Unfortunately, it happened again in my project.
On the other hand, it has not been reproduced yet in the project that only did expo init with expo-cli@3.20.0.

@katontech
Copy link
Author

Follow-up:
Even in the project that just did expo init with expo-cli@3.20.0, the symptom was reproduced about 1 hour after starting the connection with the device.
Then restart the bundler with the'r'key and the symptom reproduced in a few minutes.

@katontech
Copy link
Author

This symptom is reproduced in the project created by expo-cli@3.20.0 expo init, but the frequency is obviously lower than before.
I have a project that is stable for more than 18 hours after expo start.

In a symptomatic project, expo start with expo-cli@3.20.0 and crash in tens of minutes to minutes.

@sortinousn
Copy link

I'm not sure if it's related but I get a similar error as well. Either expo randomly crashes or crashes when I add a new package to my project.

using expo-cli@3.20.1
project packages using React Native and expo are @35.0.0

Running application on LG-H830.
events.js:173

    throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'C:\Users\josep\keepbass-rn\node_modules\@babel\generator\node_modules\.bin'
Emitted 'error' event at:
    at NodeWatcher.<anonymous> (C:\Users\josep\keepbass-rn\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:148:21)

@brentvatne
Copy link
Member

it sounds like you need to fix permissions on your machine or run everything as admin. i think the fix here isn't something we can build into expo-cli, but rather to guide people to an appropriate guide. i'm not familiar enough with windows to know what the best approach is here. cc @byCedric

@katontech
Copy link
Author

I also occasionally see an error that lstat fails when accessing node_modules\.bin, but it doesn't continue.
Rather than a static permission setting issue, maybe other processing for node_modules was happening in the background.

@sonuame
Copy link

sonuame commented Jul 20, 2020

This error is making my life hell for react development. building an apk, is becoming a nightmare for me.

@sonuame
Copy link

sonuame commented Jul 20, 2020

events.js:292
throw er; // Unhandled 'error' event
^

Error: EPERM: operation not permitted, lstat 'xxxxx\android\app\build\generated\assets\react'
Emitted 'error' event on NodeWatcher instance at:
at NodeWatcher. (xxxxxx\node_modules\sane\src\node_watcher.js:291:16)
at FSReqCallback.oncomplete (fs.js:167:21) {
errno: -4048,
code: 'EPERM',
syscall: 'lstat',
path: 'xxxxx\android\app\build\generated\assets\react'
}

@ShreyaDhir
Copy link

ShreyaDhir commented Sep 6, 2020

events.js:287
throw er; // Unhandled 'error' event
^

Error: EPERM: operation not permitted, lstat 'C:\Users\KIIT\Desktop\ProApp\node_modules.bin\atob'
Emitted 'error' event on NodeWatcher instance at:
at NodeWatcher. (C:\Users\KIIT\Desktop\ProApp\node_modules\sane\src\node_watcher.js:291:16)
at FSReqCallback.oncomplete (fs.js:167:21) {
errno: -4048,
code: 'EPERM',
syscall: 'lstat',
path: 'C:\Users\\Desktop\ProApp\node_modules\.bin\atob'
}
^
I'm getting this error.

@sonuame
Copy link

sonuame commented Sep 6, 2020

I had to quit Expo and user react-native cli in the end

@EvanBacon EvanBacon added the OS: Windows The issue is occurring on Windows label Sep 16, 2020
@NisugaJ
Copy link

NisugaJ commented Oct 4, 2020

@EvanBacon @brentvatne I also get the same issue .

Logs for your project will appear below. Press Ctrl+C to exit.
Finished building JavaScript bundle in 5920ms.
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'C:\MyProjects\<ReactNative-project-directory>\table.xsl.tmp
Emitted 'error' event at:
    at NodeWatcher.<anonymous> (C:\MyProjects\<ReactNative-project-directory>\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqWrap.oncomplete (fs.js:153:21)

Environment

  • Windows 10 : 10.0.18362 Build 18362
  • Yarn : 1.22.10
  • Expo-CLI : 3.27.10
  • Security : Kaspersky Security Cloud (File Protection is disabled )

My Questions

  1. Why does it try to write a file (table.xsl.tmp) in to AppDirectory ??
  2. What type of permission is needed ?
  3. Does it happen because it is an untrusted file ? ( I mean , are .tmp files untrusted ?)

@NisugaJ
Copy link

NisugaJ commented Oct 4, 2020

@EvanBacon @brentvatne I also get the same issue .

Logs for your project will appear below. Press Ctrl+C to exit.
Finished building JavaScript bundle in 5920ms.
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'C:\MyProjects\<ReactNative-project-directory>\table.xsl.tmp
Emitted 'error' event at:
    at NodeWatcher.<anonymous> (C:\MyProjects\<ReactNative-project-directory>\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqWrap.oncomplete (fs.js:153:21)

Environment

  • Windows 10 : 10.0.18362 Build 18362
  • Yarn : 1.22.10
  • Expo-CLI : 3.27.10
  • Security : Kaspersky Security Cloud (File Protection is disabled )

My Questions

  1. Why does it try to write a file (table.xsl.tmp) in to AppDirectory ??
  2. What type of permission is needed ?
  3. Does it happen because it is an untrusted file ? ( I mean , are .tmp files untrusted ?)

Tested now. Expo refreshes my app-changes successfully if VS Code is closed when executing expo start. But I had to add my code changes via Notepad++.
I think this issue comes because of my VS Code. Soon after I opened VS Code and did a file change, this error prompted again. Expo-server is shut-down by VS Code 😄🤣. Or maybe I should configure VS Code settings for files R/W.

Hope this result helps you 😃

@NisugaJ
Copy link

NisugaJ commented Oct 4, 2020

@EvanBacon @brentvatne I also get the same issue .

Logs for your project will appear below. Press Ctrl+C to exit.
Finished building JavaScript bundle in 5920ms.
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'C:\MyProjects\<ReactNative-project-directory>\table.xsl.tmp
Emitted 'error' event at:
    at NodeWatcher.<anonymous> (C:\MyProjects\<ReactNative-project-directory>\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqWrap.oncomplete (fs.js:153:21)

Environment

  • Windows 10 : 10.0.18362 Build 18362
  • Yarn : 1.22.10
  • Expo-CLI : 3.27.10
  • Security : Kaspersky Security Cloud (File Protection is disabled )

My Questions

  1. Why does it try to write a file (table.xsl.tmp) in to AppDirectory ??
  2. What type of permission is needed ?
  3. Does it happen because it is an untrusted file ? ( I mean , are .tmp files untrusted ?)

Tested now. Expo refreshes my app-changes successfully if VS Code is closed when executing expo start. But I had to add my code changes via Notepad++.
I think this issue comes because of my VS Code. Soon after I opened VS Code and did a file change, this error prompted again. Expo-server is shut-down by VS Code 😄🤣. Or maybe I should configure VS Code settings for files R/W.

Hope this result helps you 😃

When tried with Atom, can do some refreshing changes, but crashed prompting the same issue.

@katontech
Copy link
Author

It is interesting that the phenomenon involving the same file table.xsl.tmp as in my environment also occurred in another environment.
I've also run into the fact that it doesn't reappear in my other PC environment with the same configuration.
From this, I suspect that some external command executed by expo-cli is affected by the environmental difference.

On the other hand, I'm not too worried because I can avoid this error just by creating an empty table.xsl.tmp file.

@NisugaJ
Copy link

NisugaJ commented Oct 4, 2020

It is interesting that the phenomenon involving the same file table.xsl.tmp as in my environment also occurred in another environment.
I've also run into the fact that it doesn't reappear in my other PC environment with the same configuration.
From this, I suspect that some external command executed by expo-cli is affected by the environmental difference.

On the other hand, I'm not too worried because I can avoid this error just by creating an empty table.xsl.tmp file.

Thank you @katontech . You saved my day. Created table.xsl.tmp and it works like a charm now😍.

@brentvatne
Copy link
Member

@byCedric @fson - can one of you investigate why this table.xsl.tmp thing is going on? we do not refer to this in any way inside of our codebase so i'm confused

@katontech
Copy link
Author

I don't even know that. I also searched for the installed expo-cli code and know that table.xsl.tmp is not directly referenced.
Since expo-cli seems to work using various external tools, I imagine that there may be environmental factors that affect them.

@byCedric
Copy link
Member

byCedric commented Oct 6, 2020

None of our code, or our dependencies, refer to the file table.xsl.tmp or table.xsl. I'm not sure why this suddenly pops up for you. If someone is willing to share his/her package.json when they encounter this, I'd be happy to look into that.

We do know there are "weird behaviors" of file permissions on Windows. For example, creating a symbolic link doesn't work on Windows unless you run terminal with administrator privileges. I would heavily recommend to try that if you run into any EPERM errors with node.

But again, let's try to find the source of the table.xsl. If we find this, we can investigate why this is happening for some people and fix that instead. Fixing Windows EPERM issues isn't really possible on our end, this is a limitation from Windows itself. You can try running in WSL, that should work without problems 😄

@katontech
Copy link
Author

table.xsl.tmp is also a mystery to me. Naturally, I searched for table.xsl. * Somewhere on my PC, but I couldn't find it.
I was wondering if it was a phenomenon specific to my environment, but I am interested because there were other people who appeared table.xsl.tmp in the error message.

The phenomenon occurred by repeating the source update after expo start even if it was just after creating the project with expo init, so I think that there is no cause in the contents of package.json.

You seem to be skeptical about the "strange behavior" of Windows file permissions, but I think this is a different story as it can be reproduced in a terminal with administrator privileges.

Thanks for your comment. :-)

@Ttecs
Copy link

Ttecs commented Nov 19, 2020

events.js:287
throw er; // Unhandled 'error' event
^

Error: EPERM: operation not permitted, lstat 'C:\Users\KIIT\Desktop\ProApp\node_modules.bin\atob'
Emitted 'error' event on NodeWatcher instance at:
at NodeWatcher. (C:\Users\KIIT\Desktop\ProApp\node_modules\sane\src\node_watcher.js:291:16)
at FSReqCallback.oncomplete (fs.js:167:21) {
errno: -4048,
code: 'EPERM',
syscall: 'lstat',
path: 'C:\Users\Desktop\ProApp\node_modules.bin\atob'
}
^
I'm getting this error.

i had the same Error .i jhave kasperskysecurity and I disabled its file protection service .then eeror was gone

@tavorperry
Copy link

tavorperry commented Feb 22, 2022

This is happening to me as well.
I tried to create a new project but still.
Also occurring on web app w/o android emulate.
It suddenly happening, after 1-2 minutes of uasge

Tech info:
Windows 10.
IDE: IntelliJ / VSCode
Run expo via IDE terminal/CMD with admin permissions

Error:

Error: EPERM: operation not permitted, lstat 'D:\...\app\pages\MainPage.js~'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (D:\...\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (node:fs:198:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'D:\\...\\app\\pages\\MainPage.js~'
}

@ricjohn-acosta
Copy link

ricjohn-acosta commented Mar 1, 2022

Am also getting a similar error:

Doesn't occur on web app for me but it does happen quite often when tunneled to my ios device.

Error: EPERM: operation not permitted, lstat 'C:\Users\_\PersonalProjects\freends\screens\LoginScreen.tsx~'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (C:\Users\_\PersonalProjects\freends\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (node:fs:198:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'C:\\Users\\_\\PersonalProjects\\freends\\screens\\LoginScreen.tsx~'
}

@SohelIslamImran
Copy link

I'm getting this error

C:\Development\App\OfficeProjects\TillelIApp\node_modules\metro-hermes-compiler\src\emhermesc.js:77
          throw ex;
          ^

Error: EPERM: operation not permitted, lstat 'C:\Development\App\OfficeProjects\TillelIApp\.git\objects\maintenance.lock'       
Emitted 'error' event on NodeWatcher instance at:
    at C:\Development\App\OfficeProjects\TillelIApp\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:\\Development\\App\\OfficeProjects\\TillelIApp\\.git\\objects\\maintenance.lock'
}
error Command failed with exit code 7.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@oleg1994
Copy link

I'm getting this error

C:\Development\App\OfficeProjects\TillelIApp\node_modules\metro-hermes-compiler\src\emhermesc.js:77
          throw ex;
          ^

Error: EPERM: operation not permitted, lstat 'C:\Development\App\OfficeProjects\TillelIApp\.git\objects\maintenance.lock'       
Emitted 'error' event on NodeWatcher instance at:
    at C:\Development\App\OfficeProjects\TillelIApp\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:\\Development\\App\\OfficeProjects\\TillelIApp\\.git\\objects\\maintenance.lock'
}
error Command failed with exit code 7.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

yep getting the same error

@MaiconGavazzoni
Copy link

Tente correr no terminal do VsCode yarn react-native run-android --port 8082

@KingAmo
Copy link

KingAmo commented Aug 9, 2022

Go to 'System preference' -> 'Security & Privacy' -> scroll down and click 'Full Disk Access' -> Make sure you checked on 'Terminal' and 'Watchman'.

@raajnadar
Copy link

Go to 'System preference' -> 'Security & Privacy' -> scroll down and click 'Full Disk Access' -> Make sure you checked on 'Terminal' and 'Watchman'.

There is no Watchman on my settings, any idea why?

I am working on macOS Monterey version 12.5

@paterninajose
Copy link

paterninajose commented Sep 7, 2022

Hey guys. I'm dealing with this error for about 1 month now and it's exponential, 1 per day and now every 5 minutes, but I think it's because I increased git branch activities and writing code while compiling (e.g. run android).

I found a solution.

My Environment:

- Windows v10
- VsCode v1.62.3
- Expo v6.0.5

Error: EPERM: operation not permitted, lstat ... node_modules\metro-hermes-compiler\src\emhermesc.js:77 -any file-.lock

What I think is happening:

graph TD;
    VsCode_LockThat-->android,git,etc;
    ExpoMetro_LockThat-->android,git,etc;
    android,git,etc-->EPERM,lstat;
    EPERM,lstat-->ExpoCrash;

And that's why opening as administrator any software (Terminal, VsCode) didn't work.
Two software with the same locking power always will crash. Deadlock?.

Solution that worked for me:

https://forums.expo.dev/t/error-eperm-operation-not-permitted-lstat/19221
Open your metro.config.js file and include these lines (all before the last line module.exports = defaultConfig;):

const blackList = /.*git.*|.*android.*|.*__fixtures__.*|.*node_modules.*|.*react.*|.*dist.*|.*website\\node_modules.*|.heapCapture\\bundle.js|.*__tests__.*/gm

module.exports = {
	resolver: {
		blockList: blackList,
		blackListRE: blackList,
	}
};

I updated the previous answer, due metro-config guys has been changing blacklistRE to excludeList and now is blockList.

💡Note: Okay, if it doesn't work for you, follow these instructions (launch VsCode from WSL Ubuntu terminal on Windows):
https://code.visualstudio.com/docs/remote/wsl
You must remove android and node_modules folder, install and compile again from the WSL console. It works smoothly.

@yume-chan
Copy link

For me, the most troublemaking one is .git\objects\maintenance.lock. After some investigation, it should be caused by VS Code periodically running git fetch, which then automatically invokes git maintentance (https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---no-auto-maintenance), which creates and holds this lock file.

But I can't workaround this by using metro.config.js. I'm using managed flow, so I changed my metro.config.js to

// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

const blockList = /\\__tests__\\.*|\\.git\\.*/

const defaultConfig = getDefaultConfig(__dirname);

module.exports = {
  ...defaultConfig,
  resolver: {
    ...defaultConfig.resolver,
    blockList,
  }
};

However, it still crashes with the same error time to time.

@yume-chan
Copy link

yume-chan commented Dec 26, 2022

For git related errors, the root cause is facebook/metro#553, it only accepts Linux path separator even on Windows, so I shouldn't use \\, also it gives relative paths so no leading \\. This should work:

const blockList = /.git/

@krmao
Copy link

krmao commented Apr 16, 2023

Hey guys. I'm dealing with this error for about 1 month now and it's exponential, 1 per day and now every 5 minutes, but I think it's because I increased git branch activities and writing code while compiling (e.g. run android).

I found a solution.

My Environment:

- Windows v10
- VsCode v1.62.3
- Expo v6.0.5

Error: EPERM: operation not permitted, lstat ... node_modules\metro-hermes-compiler\src\emhermesc.js:77 -any file-.lock

What I think is happening:

And that's why opening as administrator any software (Terminal, VsCode) didn't work. Two software with the same locking power always will crash. Deadlock?.

Solution that worked for me:

https://forums.expo.dev/t/error-eperm-operation-not-permitted-lstat/19221 Open your metro.config.js file and include these lines (all before the last line module.exports = defaultConfig;):

const blackList = /.*git.*|.*android.*|.*__fixtures__.*|.*node_modules.*|.*react.*|.*dist.*|.*website\\node_modules.*|.heapCapture\\bundle.js|.*__tests__.*/gm

module.exports = {
	resolver: {
		blockList: blackList,
		blackListRE: blackList,
	}
};

I updated the previous answer, due metro-config guys has been changing blacklistRE to excludeList and now is blockList.

💡Note: Okay, if it doesn't work for you, follow these instructions (launch VsCode from WSL Ubuntu terminal on Windows): https://code.visualstudio.com/docs/remote/wsl You must remove android and node_modules folder, install and compile again from the WSL console. It works smoothly.

mrousavy/react-native-vision-camera#1047 (comment)

@byCedric byCedric removed their assignment Jan 4, 2024
@byCedric
Copy link
Member

byCedric commented Jan 5, 2024

Hi all! Since this seems like an issue in Metro itself, let's keep the discussion central inside facebook/metro#553

Closing this issue, related to Metro.

@byCedric byCedric closed this as completed Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error message improvement needed OS: Windows The issue is occurring on Windows
Projects
None yet
Development

No branches or pull requests