react-native: Windows & Android: react native server crashes very often

 ERROR  EPERM: operation not permitted, lstat '...\.idea\workspace.xml___jb_old___'
{"errno":-4048,"code":"EPERM","syscall":"lstat","path":"...\.idea\\workspace.xml___jb_old___"}
Error: EPERM: operation not permitted, lstat 'app\.idea\workspace.xml___jb_old___'
    at Error (native)

After that I should again do:

npm start

How to resolve this quite annoying problem? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 7
  • Comments: 77 (6 by maintainers)

Most upvoted comments

@ericnakagawa I think this issue should be reopened

For the record:

  • I tried Watchman on Windows without success (It bundles nothing(!) and app won’t run. As stated in this ticket https://github.com/facebook/react-native/issues/7022).
  • Then tried to disable inspection of my git files (lstat error was almost always on my .git/index.lock) by defining getBlacklistRE in my rn-cli.config.js but it didn’t help either.

The only temporarily workaround I found was to change behavior of react cli on exceptions. Open node_modules/react-native/local-cli/server/server.js find process.on('uncaughtException', line and comment process.exit(1); at the end to completely disable quit on exception.

@pvllnspk @minhchu I’ll be closing this issue since it looks like it is resolved since v0.37 and we are now at v0.37

Expanding on @withparadox2 solution:

This solved the issue for me on: react-native-cli: 2.0.1 react-native: 0.35.0

Create the following rn-cli.config.js file in your project’s root directory containing something similar to this (change as you see fit):

let blacklist = require('react-native/packager/blacklist');
let config = {
    getBlacklistRE(platform) {
        return blacklist(platform, [
            // Ignore local `.sample.js` files.
            /.*\.sample\.js$/,

            // Ignore IntelliJ directories
            /.*\.idea\/.*/,
            // ignore git directories
            /.*\.git\/.*/,
            // Ignore android directories
            /.*\/app\/build\/.*/,

            // Add more regexes here for paths which should be blacklisted from the packager.
        ]);
    }
};
module.exports = config;

Confirm problem on Windows 7, react-native@0.40.0

 ERROR  EPERM: operation not permitted, lstat 'd:\project\project\.git\index.lock'
{"errno":-4048,"code":"EPERM","syscall":"lstat","path":"d:\\project\\project\\.git\\index.lock"}
Error: EPERM: operation not permitted, lstat 'd:\project\project\.git\index.lock'
    at Error (native)

See http://facebook.github.io/react-native/docs/troubleshooting.html
for common problems and solutions.

I’ve been using VSCode as well and faced the same problem. Since VSCode has no option like “safe write” that Webstorm got, i’ve set 2 options in the settings file of VSCode editor.

File -> Preferences -> Settings

Added:

“git.autorefresh”: false, “git.autofetch”: false,

This seemed to do the trick, i do not know if those options actually prevent the git file of being updated all the time you save changes to your code. I haven’t faced the error message since then. Hope it helps someone.

Edit: By the way, as the settings above will deactivate the auto refresh VSCode holds with the Git status, whenever you need to check how many changes were made to the project, you just have to click on the Git button on the editor and it will update its status.

This should resolve the issue for now.

In case the answer gets deleted, the solution is to go to File > Settings > System Settings > Synchronization. And uncheck Use "safe write" (save changes to a temporary file first).

Obviously this isn’t a long term solution as it’s checked by default for a reason.

My issue came from having run vscode as an admin which created build folders my own user didn’t have permissions on. Manually removed build folders and reset permissions solved it for me.

Hello, I had the same problem on windows 10 , I could fix it following the next steps: Run one by one 1. go to folder android into your project and run gradlew clean.

2. return to root folder of your project and run react-native start. wait until React Packager is ready and says: “loading dependency graph, done”.

3. now run react-native run-android.

If all is right you project should run in your Emulator whitout problems.

I hope works for you as It works for me.

I solve the problem by install watchman. The same issues gave the method: https://github.com/facebook/react-native/issues/4204 watchman: https://facebook.github.io/watchman/ download url is: http://bit.ly/watchmanwinalpha windows is still alpha support, see this: https://github.com/facebook/watchman/issues/19 after extract watchman and set path env, restart idea, the problem do not happend again.

I got the same problem after i modified a js file. I try modifying project directory‘s access level, grant total access permission to all users, but on work. It seems the packager program 's run time user has no permission. I don’t know. Hope somebody help.

now the rn-cli.config.js become these:

let blacklist = require('metro-bundler/src/blacklist');

let config = {
	getBlacklistRE() {
		return blacklist([
			// Ignore local `.sample.js` files.
			/.*\.sample\.js$/,

			// Ignore IntelliJ directories
			/.*\.idea\/.*/,
			// ignore git directories
			/.*\.git\/.*/,
			// Ignore android directories
			/.*\/app\/build\/.*/

			// Add more regexes here for paths which should be blacklisted from the packager.
		]);
	}
};
module.exports = config;


i have tried in : win10 react-native-cli: 2.0.1 react-native: 0.50.4

now the dev server won’t be interupted by “lstat err” due to the rebuild process of android app

Thanks @codebymikey , It works well for me through the solution, In Webstorm, uncheck “File->Settings->System Settings->sychronization->use safe write” I’m Win10, use Webstorm

This is still happening on RN 0.45.1 (at least on windows), and from all the comments it looks like a race condition against the filesystem. I think if lstat() fails and the file doesn’t exist, it should simply not be considered an error.

These kinds of problems are really common when dealing with a filesystem outside of the control of the application. Almost nothing should be assumed about the filesystem structure from one second to the next.

Can I help somehow? Is there someone still working on a fix for this?

Turned off Atom (editor) and Android Studio and tried again, Worked like a charm. Probably Android Studio indexing is interfering with npm.

error: package com.facebook.reactnative.androidsdk does not exist

install android SDK… https://facebook.github.io/react-native/docs/getting-started.html#3-install-the-android-6-0-marshmallow-sdk

BTW Have you followed the instructions by details?

This is stackoverflow… not a issue with react-native

Hmmm. I perhaps spoke too soon. While the above may have helped (hard to tell – I don’t want to replicate the old state to confirm), I then found I was still getting errors a couple builds later.

However, I believe I’ve fixed it fully now, by using watchman, as recommended by @chardlau here: https://github.com/facebook/react-native/issues/9136#issuecomment-236767931

However, the link he gave is outdated. The latest version can be obtained here: https://facebook.github.io/watchman/docs/install.html

Also note that, in my project, I had some pretty deep issues when switching over to watchman at first. I’ve been working on the fixes for these for the last 5 hours, but I’ve finally got them fixed, and the project building again. (it required me to make some changes in the node_modules)

~~I don’t really have time to go over the details of the problems I had switching to watchman (unless someone else actually hits the same problem, anyway), but I’ve summarized some basic parts of it here: https://github.com/Venryx/LucidLink/blob/master/Troubleshooting.md~~

EDIT

I’ve since found the root cause of the watchman issues: the paths were not being normalized in the jest-haste-map module, causing duplicate entries, and “misses” when calling hasteMap.exists().

I reported the issue here, along with the solution: https://github.com/facebook/jest/issues/3752

So in other words, to solve the “ERROR EPERM: operation not permitted, lstat” problem:

  1. Install watchman, and add it to your path: https://facebook.github.io/watchman/docs/install.html
  2. Make the changes to the jest-haste-map file, as seen here (if you encounter the duplicate-module warnings and module-not-found errors): https://github.com/facebook/jest/issues/3752
  3. [edit] Oh, you might also need this, in a “.watchmanconfig” file in your project root. I don’t seem to need it in mine, but it’s worth mentioning in case it’s needed in other people’s cases.
{
	"ignore_dirs": [
		"android"
	]
}

Also, note that when running “react-native start” to start the packager, in some cases it might be necessary to add the “–resetCache” flag. I’ve had some issues in my debugging process where cached files were kept, causing my latest “react-native start” to not recreate all the files. (either causing problems, or hiding problems)

On every build I get the same problem. The packager crashes since it is watching files that are deleted or modified during build.

Typical error:

ERROR  ENOENT: no such file or directory, scandir 'C:\projects\foo\android\app\build\intermediates\res\merged\bar\release\values-xlarge-v4'
{"errno":-4058,"code":"ENOENT","syscall":"scandir","path":"C:\\projects\\foo\\android\\app\\build\\intermediates\\res\\merged\\bar\\release\\values-xlarge-v4"}
Error: ENOENT: no such file or directory, scandir 'C:\projects\foo\android\app\build\intermediates\res\merged\bar\release\values-xlarge-v4'

The actual file it crashes on varies, but always in the android\app\build folder.

I tried the suggestion to add a rn-cli.config.js file like earlier in the thread, specifically telling it to ignore android/app, but that makes no difference.

Windows 10 react-native-cli: 2.0.1 react-native: 0.43.4

Whenever Android Studio starts gradle sync or to process files in the appdir. the watchdog on react-native will die with this error. Try to start simulator from console or start simulator from Android studio, then run react-native run-android close android studio and develop…

On win7, with VSCode and SourceTree, sometimes got that crash.

This work for me: react-native start And when the load is complete type: react-native run-android

Should be reopened, can confirm I’m getting this issue on RN 0.40

I encounter this issue with v0.40 ONLY when including ‘react-native-camera’ library.

  • Error in the “react-native run-android” console:

` FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:app:prepareMobileAppReactNativeCameraUnspecifiedL ibrary’.

Could not expand ZIP ‘E:\react-native\MobileApp\node_modules\react-native-c amera\android\build\outputs\aar\react-native-camera-release.aar’.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4 mins 35.965 secs Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/android-setup.html

(node:3816) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec tion id: 2): TypeError: Cannot read property ‘message’ of undefined `

  • Errror in React Packager console: ERROR EPERM: operation not permitted, lstat 'E:\react-native\MobileApp\andr oid\app\build\intermediates\exploded-aar\MobileApp\react-native-camera\unspec ified\aapt\AndroidManifest.xml' {"errno":-4048,"code":"EPERM","syscall":"lstat","path":"E:\\react-native\\MobileApp\\android\\app\\build\\intermediates\\exploded-aar\\MobileApp\\react-na tive-camera\\unspecified\\aapt\\AndroidManifest.xml"} Error: EPERM: operation not permitted, lstat 'E:\react-native\MobileApp\andro id\app\build\intermediates\exploded-aar\MobileApp\react-native-camera\unspeci fied\aapt\AndroidManifest.xml' at Error (native)

any news?

I think I find another solution, but not quite sure, help me check it. After crawling files, a watcher will be added on these files, so what if I ignore such files under .idea?

Add one method in local-cli\default.config.js

  getBlacklistREMore(platform, additionalList) {
    return blacklist(platform, additionalList);
  },

Change code of method getPackagerServer In local-cli\server\runServer.js from blacklistRE: config.getBlacklistRE(), to blacklistRE: config.getBlacklistREMore(null, [/\.idea.*/]),

Done. Let me know if anything described here is wrong.