Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows & Android: react native server crashes very often #9136

Closed
pvllnspk opened this issue Aug 1, 2016 · 77 comments
Closed

Windows & Android: react native server crashes very often #9136

pvllnspk opened this issue Aug 1, 2016 · 77 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@pvllnspk
Copy link

pvllnspk commented Aug 1, 2016

 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

@chardlau
Copy link

chardlau commented Aug 2, 2016

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.

@chardlau
Copy link

chardlau commented Aug 2, 2016

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

@withparadox2
Copy link

@chardlau doesn't solve my problem, I have no idea why just adding watchman to env path can avoid such error

@withparadox2
Copy link

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.

@pvllnspk
Copy link
Author

pvllnspk commented Aug 2, 2016

Now it cries about build folder
\build\generated\source\r\debug\android\support\design\R.java'
@withparadox2 How to properly handle it?

@withparadox2
Copy link

withparadox2 commented Aug 2, 2016

@pvllnspk I have never come cross errors like yours, could you paste the detail message? And need to tell you the truth I got the error again after the server running for several hours, it's still related to 'workspace.xml___jb_old___'.

@pvllnspk
Copy link
Author

pvllnspk commented Aug 2, 2016

@withparadox2, so seems like we need to find another solution, let's keep in touch

@pvllnspk
Copy link
Author

pvllnspk commented Aug 4, 2016

any news?

@pvllnspk
Copy link
Author

pvllnspk commented Aug 8, 2016

@Rmaan
Copy link

Rmaan commented Sep 21, 2016

For the record:

  • I tried Watchman on Windows without success (It bundles nothing(!) and app won't run. As stated in this ticket Enabling Watchman on Windows causes JS errors #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.

@ericnakagawa
Copy link
Contributor

Hi folks, are you folks still experiencing this issue?

@minhchu
Copy link

minhchu commented Jan 10, 2017

I didnt experience this issue from RN v0.37 (still crash on 0.36 very often)

@anthony-skr
Copy link

Experiencing the same on 0.39.2 with .idea and .git folders

@ericnakagawa
Copy link
Contributor

@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

@ptol
Copy link

ptol commented Jan 17, 2017

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

The problem still exists with v0.40

@viettranme
Copy link

viettranme commented Jan 19, 2017

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)

@Sanford284
Copy link

The problem still exists with v0.40.
At the time error is occuring, the windows's taskbar will be stop, only restart system.

@prattpratt
Copy link

Confirm problem on Windows 7, [email protected]

 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.

@wilomgfx
Copy link

Same here. Windows 7, [email protected]
On WebStorm.
image

@prattpratt
Copy link

This become really annoying :( I can't work in normal flow.

@user471
Copy link

user471 commented Jan 23, 2017

@ericnakagawa I think this issue should be reopened

@wilomgfx
Copy link

@ericnakagawa totally should be reopened.

@petersobolev
Copy link

Same problem, RN 0.40.0, Win7

@Sanford284
Copy link

I hava solved it. see http://blog.csdn.net/real_bird/article/details/54691589

@Rmaan
Copy link

Rmaan commented Jan 24, 2017

Is this a Windows 7 specific problem? Does anybody experiencing this issue with Windows 10?

@scavezze
Copy link

I have the same issue v 0.38 can i just tell that packager to ignore certain folders

@codetony25
Copy link

+1 having this issue on React Native 0.39.2

@omerdn1
Copy link

omerdn1 commented Jan 31, 2017

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

@43081j
Copy link

43081j commented Apr 17, 2017

This still happens for me...

> react-native --version
react-native-cli: 2.0.1
react-native: 0.43.3

In procmon, I see a huge amount of file operations with status "BUFFER OVERFLOW", could be related? I forgot buffer overflows are just buffer length checks...

Seems when anything that isn't the packager tries to access the same files, the packager throws a fit. It won't run again until I remove my node_modules and re-install (yarn). So my guess is something bad going on with open file handles, etc...

Also do note, I use vim and CLI, so you can rule out any editor/android studio/etc I guess.

Almost always, too, the lstat errors are on .git paths and node_modules/.bin paths.

This issue really shouldn't be closed, I suggest you re-open it @ericnakagawa.

@Dashue
Copy link

Dashue commented Apr 17, 2017 via email

@43081j
Copy link

43081j commented Apr 17, 2017

Right now I'm pretty much running it all outside any editor and have always been:

  • Run emulator -avd API_23 (my AVD i setup)
  • Run react-native start (works first time)
  • Run react-native run-android (this launches start if it isn't already running, too)
  • Either install a new dependency (yarn add foo), or do some git operations (e.g. commit something)

Result is an unknown lstat error (code -4094).

I've stepped through the packager and broke on the exception, but its literally just an lstat error, no useful information.

Re-running the packager after it has errored results in the same error (sometimes on a different path). So at this point it no longer functions at all.

The only solution I found is to trash the entire node_modules directory and re-install it all, presumably because the mass of file handles it has open get freed... (its monitoring node_modules by the looks of it, thats potentially a huge tree).

Also sounds like the solution way up above, of running a clean build in android studio, is solving the problem the same way my node_modules deletion is? Basically if you delete a load of files the packager was watching, it works. Sounds like too many watches to me...

@codebymikey
Copy link

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;

@dcp12345678
Copy link

dcp12345678 commented Apr 21, 2017

I had this problem as well after upgrading to react-native 0.43.4 using react-native-git-upgrade. I use Visual Studio Code on Windows 7 and run on the Android Emulator that comes with Android Studio. Here is the solution that worked for me:

  1. Close any running instances of android emulator and react packager.
  2. Under <your_project_folder>/android, remove the build folder and all its contents.
  3. Under <your_project_folder>/android/app, remove the build folder and all its contents
  4. Go back to your project folder and do 'react-native run-android', and with any luck, your project will run.

@pierre-H
Copy link

I have the same problem.

I use VS Code 1.11.2, Windows 7 and create-react-native-app.
The problem started since I did git init.

Any solution ?
@ericnakagawa this issue should be re-opened

@llioor
Copy link

llioor commented Apr 25, 2017

@pierre-H check my solution up.

@pierre-H
Copy link

@llioor There is no android folder with creact-react-native-app

@llioor
Copy link

llioor commented Apr 25, 2017

@pierre-H
If you are working with create native app so open issue on their git repo because it is not related to the same issue.. the current issue is realted to the "build" folder and you are not working with build folder until you are not "eject" from "create react native app".

If you want, go through these steps: https://facebook.github.io/react-native/docs/getting-started.html and if you have the same issue as mentioned in the first comment here so check my solution.

@fgeorgsson
Copy link

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

@llioor
Copy link

llioor commented Apr 26, 2017

@PCguru did you read all comments in this post?
Solution found:
http://stackoverflow.com/a/43217182/2862728

@fgeorgsson
Copy link

We're not using react-native-fbsdk.

The packager shouldn't be monitoring the build folder.

@Venryx
Copy link
Contributor

Venryx commented Jun 5, 2017

@PCguru Newer versions of react-native apparently use a different signature for blacklisting -- you're supposed to no longer include the "platform" parameter.

So @codebymikey's solution here should work, except instead of:

[...]
    getBlacklistRE(platform) {
        return blacklist(platform, [
            [...]
        ]);
    }
[...]

It should now be:

[...]
    getBlacklistRE() {
        return blacklist([
            [...]
        ]);
    }
[...]

For reference, see here and here.

For me, with:
react-native-cli: 2.0.1
react-native: 0.42.0-rc.3

This finally worked! Solved the agonizing, horrible process of deleting the entire build folder every time I wanted to change anything in the Java code.

Really, the blacklist function should throw an error or something, if it has an extra parameter... would save some headaches for people following outdated blacklisting code. (it currently just fails completely silently)

EDIT: Actually, this didn't solve it. See below for a working solution.

@Venryx
Copy link
Contributor

Venryx commented Jun 6, 2017

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: #9136 (comment)

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: jestjs/jest#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): Paths are not normalized on Windows, causing duplicates jestjs/jest#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)

@Venryx
Copy link
Contributor

Venryx commented Jun 7, 2017

I've found a second solution.

  1. Move your index.android.js entry file into the src folder.
  2. Update your android/app/build.gradle file:
project.ext.react = [
    // the entry file for bundle generation
-    entryFile: "index.android.js",
+    entryFile: "src/index.android.js",
    extraPackagerArgs: ["--sourcemap-output", file("$buildDir/outputs/index.android.js.map")],
];
  1. Update your android\app\src\main\java\v\<project name>\MainApplication.java file:
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected String getJSMainModuleName() {
-            return "index.android";
+            return "src/index.android";
        }
  1. Create an rn-cli.config.js file in your project's root, with these contents:
var path = require("path");
let config = {
    getProjectRoots() {
        return [path.resolve("node_modules"), path.resolve("src")];
    },
};
module.exports = config;

What this does is it removes the need for the blacklist -- it just doesn't even start processing anything other than what's in "src" and "node_modules". This means, when you build your project, the file-changes in "android" are not even on the radar. (Of course, if you make Java/Android changes within the "node_modules" folder and build them, the packager may crash. But this is not very common, so it's okay.)

So why does this work, but not the "ignore list"? I think it's because the file-watcher system does some operations even on "ignored" paths -- it doesn't do the full processing, but still calls "lstat" on the files. (In my project, paths which were ignored, and confirmed as such with custom code in various places in react-native's js files, still showed up in errors for an "lstat" operation in the packager process -- unfortunately, the stack trace just said "Error (native)" or something. Of course, the ignore-not-fully-ignoring might also just be a side-effect of the non-normalized-paths-causing-duplicate-entries issue mentioned in my previous post.)

So anyway, if the above solution of using watchman doesn't work, you can try this one as well. (I'm currently going with the watchman solution, however, since I've read that it's somewhat faster)

Phew! Anyway, hope I can finally close the book on this one...

@Aroniez
Copy link

Aroniez commented Jul 3, 2017

Still same problem in Win 7 with the following versions
react-native-cli: 2.0.1
react-native: 0.44.2

@ashikjs
Copy link

ashikjs commented Jul 11, 2017

@facosta0787
Copy link

facosta0787 commented Jul 27, 2017

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.

@hiteshsahu
Copy link

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

@mallelapavank
Copy link

@hiteshsahu This worked in my case. I closed both Android Studio and Atom, then ran react-native run-android. Build was successful with no errors

@Venryx
Copy link
Contributor

Venryx commented Nov 21, 2017

I've written a new Stack Overflow answer which sums up and extends a bit on the solution(s) presented above: https://stackoverflow.com/a/47420765/2441655

It doesn't require the developer to close the react-native packager or Android Studio, or call "gradlew clean"; which is nice, since those workarounds are annoying and eat away at your sanity.

My earlier posts (a couple pages up) are less clear because at the time I didn't understand the distinction between the two issues. (That, and there was a third issue in the "jest" module which made one of those two issues much harder to diagnose/debug -- the third issue is fixed now if you're using the latest versions, so doesn't need to be worked around anymore)

@ddaeschler
Copy link

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?

@fatfatson
Copy link

https://facebook.github.io/watchman/docs/config.html

On Linux systems, ignore_dirs is respected at the OS level; the kernel simply will not tell watchman about changes to ignored dirs. macOS and Windows have limited or no support for this, so watchman needs to process and ignore this class of change.

i think that's why .watchmanconfig.ignore_dirs=["android"] not work!

@fatfatson
Copy link

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

@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests