metro icon indicating copy to clipboard operation
metro copied to clipboard

Error: EISDIR: illegal operation on a directory, read

Open huhuang03 opened this issue 3 years ago • 29 comments

Do you want to request a feature or report a bug? A bug I think.

What is the current behavior?

I have an project which is a react native project called th_views.rn and in the project there's a folder which is still a react native project named examples

Then I run npm run android in examples which run the react-native run-android. Then the error show:

file:  /my_porject_path/th_views.rn/examples/.
Error: EISDIR: illegal operation on a directory, read
    at Object.readSync (node:fs:625:3)
    at tryReadSync (node:fs:390:20)
    at Object.readFileSync (node:fs:427:19)
    at UnableToResolveError.buildCodeFrameMessage (/Volumes/wd/Previous Content/source/th_libs/rn/th_views.rn/examples/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:347:17)
    at new UnableToResolveError (/Volumes/wd/Previous Content/source/th_libs/rn/th_views.rn/examples/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:333:35)
    at ModuleResolver.resolveDependency (/Volumes/wd/Previous Content/source/th_libs/rn/th_views.rn/examples/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:211:15)
    at DependencyGraph.resolveDependency (/Volumes/wd/Previous Content/source/th_libs/rn/th_views.rn/examples/node_modules/metro/src/node-haste/DependencyGraph.js:413:43)
    at /Volumes/wd/Previous Content/source/th_libs/rn/th_views.rn/examples/node_modules/metro/src/lib/transformHelpers.js:317:42
    at /Volumes/wd/Previous Content/source/th_libs/rn/th_views.rn/examples/node_modules/metro/src/Server.js:1471:14
    at Generator.next (<anonymous>)

which the code around is node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:

  buildCodeFrameMessage() {
    let file;

    try {
      file = fs.readFileSync(this.originModulePath, "utf8");
    } catch (error) {
      if (error.code === "ENOENT") {
        // We're probably dealing with a virtualised file system where
        // `this.originModulePath` doesn't actually exist on disk.
        // We can't show a code frame, but there's no need to let this I/O
        // error shadow the original module resolution error.
        return null;
      }

      
      // I add for show the folder
      console.log("file: ", this.originModulePath)
      throw error;
    }

And the folder which perform read on is: /my_porject_path/th_views.rn/examples/.

It's strange that perform read on .. How can I debug or fix this. Thank you.

huhuang03 avatar Apr 09 '21 02:04 huhuang03

+1

supermaverickws avatar Apr 09 '21 04:04 supermaverickws

Got the same issue

hraschan avatar Apr 14 '21 10:04 hraschan

i am getting the same issue running on iOS... my app is hanging on splash screen with the same error message.
@huhuang03 did you find any fix for this ?

Vishal0201 avatar Apr 16 '21 06:04 Vishal0201

Got the same issue

darrychen92 avatar Apr 16 '21 09:04 darrychen92

It seems like that the error occurs when I open Devtools.

I solved that according to the highest answer in this question https://stackoverflow.com/questions/61339968/devtools-failed-to-load-sourcemap-could-not-load-content-for-chrome-extension

darrychen92 avatar Apr 16 '21 09:04 darrychen92

@huhuang03 : did you find any solution for this. we are struggling to get the solution. Please let us know if you got anything

agrawalsurabhi89 avatar Apr 16 '21 10:04 agrawalsurabhi89

@agrawalsurabhi89 Sorry I didn't...

huhuang03 avatar Apr 27 '21 02:04 huhuang03

@huhuang03 Disable the Google debugging tool JavaScript Source Maps and CSS Source Map, The error goes away

JohnZengshi avatar Apr 27 '21 03:04 JohnZengshi

Same here, trying to upgrade an app from Expo SDK 40 to 41.

An error in devtools related to source maps:

http://localhost:19000/debugger-ui/debuggerWorker.aca173c4.js.map

image

image

This is just annoying to have a console stacktrace on expo start, but it does not prevent the app to run in my case.

slorber avatar Apr 28 '21 17:04 slorber

It seems like that the error occurs when I open Devtools.

I solved that according to the highest answer in this question https://stackoverflow.com/questions/61339968/devtools-failed-to-load-sourcemap-could-not-load-content-for-chrome-extension

Can you share the link to the answer to be more accurate? Also it is true, I can only reproduce while debugging. if not the issue does not arise.

nicoabie avatar Jun 06 '21 23:06 nicoabie

Go to the developer tools (F12 in the browser), then select the three dots in the upper right corner, and go to Settings. Then, look for Sources, and disable the options: "Enable javascript source maps" "Enable CSS source maps"

Same issue here; assuming the stackoverflow url posted above is the quote above - this did not work. Same experience though, when I am not debugging the error magically goes away.

cw-dos avatar Jun 17 '21 03:06 cw-dos

I'm facing the sam issue. If this is gonna help somebody - attaching the debugger via react-native-debugger app works like a charm.

image

lpetka avatar Jul 12 '21 14:07 lpetka

@lpetka please can you expatiate on your suggestion? How did you attach the debugger via react-native-debugger?

akinwale-habibullah avatar Aug 02 '21 07:08 akinwale-habibullah

I have installed [email protected] and this fixed my issues (after all warnings resolved and recommended versions installed)

ruvaleev avatar Sep 08 '21 13:09 ruvaleev

I have installed [email protected] and the issue still persists :( MacOs Big Sur

whisher avatar Oct 03 '21 10:10 whisher

Same here, failing to resolve /my-root/. originating in requestProcessor()

[email protected] [email protected] node v14.18.0 npm v8.0.0

Error: EISDIR: illegal operation on a directory, read
    at Object.readSync (fs.js:617:3)
    at Object.readSync (/my-root/app/my-app/node_modules/graceful-fs/polyfills.js:147:28)
    at tryReadSync (fs.js:382:20)
    at Object.readFileSync (fs.js:419:19)
    at UnableToResolveError.buildCodeFrameMessage (/my-root/app/my-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:304:17)
    at new UnableToResolveError (/my-root/app/my-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:290:35)
    at ModuleResolver.resolveDependency (/my-root/app/my-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:168:15)
    at DependencyGraph.resolveDependency (/my-root/app/my-app/node_modules/metro/src/node-haste/DependencyGraph.js:353:43)
    at /my-root/app/my-app/node_modules/metro/src/lib/transformHelpers.js:271:42
    at Server.<anonymous> (/my-root/app/my-app/node_modules/metro/src/Server.js:842:41)

rodneyrehm avatar Oct 13 '21 17:10 rodneyrehm

still got the same issue

prawee avatar Oct 16 '21 10:10 prawee

i am stuck since 2 days... can anyone please post a solution...

jyotiprakash111 avatar Oct 18 '21 09:10 jyotiprakash111

For what it's worth... I still see this error and i've continued to ignore it. Everything in my app is working fine, my store builds work fine so until it breaks something I'll unfortunately continue to ignore it. I may try the solution mentioned by @lpetka; as it appears to be related to the debugger.

cw-dos avatar Oct 18 '21 14:10 cw-dos

I've the same issue. I've solve it by adding to metro.config.js next lines :

module.exports = (() => {
	return {
		resolver: {
			sourceExts: ['cjs', 'js', 'ts', 'jsx', 'tsx'], // Adding here all needed extensions in your app
		},
	}
})()

I hope this can help you

trykers avatar Dec 11 '21 11:12 trykers

i solved by this link here https://stackoverflow.com/questions/70405285/react-native-android-crashes-on-enabling-debug-mode ,react-native-reanimated no support on debug mode , some of the plugin no support debug mode, don't forget to check the plugin you install

cavab97 avatar Jan 12 '22 14:01 cavab97

I got the same issue:

`

Error
Error: EISDIR: illegal operation on a directory, read
   at Object.readSync (node:fs:723:3)
   at tryReadSync (node:fs:433:20)
   at Object.readFileSync (node:fs:479:19)
   at UnableToResolveError.buildCodeFrameMessage (node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:347:17)
   at new UnableToResolveError (/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:333:35)
   at ModuleResolver.resolveDependency (node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:211:15)
   at DependencyGraph.resolveDependency (node_modules/metro/src/node-haste/DependencyGraph.js:413:43)
   at node_modules/metro/src/lib/transformHelpers.js:317:42
   at node_modules/metro/src/Server.js:1471:14
   at Generator.next (<anonymous>)
`

[email protected] [email protected] node v16.14.0 yarn v1.22.17 MacOs Big Sur

But in my case I also can see this issue in my build. How can I fix this. Thank you.

kburisma avatar Feb 17 '22 10:02 kburisma

bit of a old thread but i just solved this exact issue on a server I am running.

my issue was that i was using "readFileSync", when it came across a Directory and not a file, it threw that error.

my solution was simply re organize my file structure so that it does not come across a folder, for others you may want to implement some logic to not read a Directory's only files.

you1307 avatar Feb 18 '22 01:02 you1307

I got same error, but all going well after I yarn global remove wml

yarn global remove wml

that save my life

if you have never install wml, just consider some other related global libs

----update----- I got the error again even I uninstall wml staff, but I found my issue's root cause was the watchman, after run brew uninstall watchman, all going well

jiyuan12354 avatar Mar 30 '22 07:03 jiyuan12354

@huhuang03 Disable the Google debugging tool JavaScript Source Maps and CSS Source Map, The error goes away

This is not a valid answer. The issue isn't about displaying an error. It's about the debugger preventing the app from loading, in my case.

mjstelly avatar Apr 18 '22 17:04 mjstelly

I'm facing the sam issue. If this is gonna help somebody - attaching the debugger via react-native-debugger app works like a charm.

image

I'm glad it worked for you although I can't see how it did. RN Debugger is built on Chrome Devtools. If open, it redirects the app launch away from Devtools. I thought I'd try your solution hoping it'd work for me. Sadly, it did not.

mjstelly avatar Apr 19 '22 18:04 mjstelly

For what it's worth... I still see this error and i've continued to ignore it. Everything in my app is working fine, my store builds work fine so until it breaks something I'll unfortunately continue to ignore it. I may try the solution mentioned by @lpetka; as it appears to be related to the debugger.

Unlike the OP, my app runs fine and I don't receive this error message as long as I don't try to launch a debugger. Once in debug mode, the app hangs at the splash screen. If I close the debugger, then app refreshes and works as intended. The really weird part of this is that this error just started appearing about 2 days ago. Before that, I used the debugger daily. No frikin idea what's going on.

What's even more surprising is that this issue has remained open for over a year now. UPATE: I guess in my case, the problem resides with the react-native-reanimated library. There's a known bug that breaks the debugger.

mjstelly avatar Apr 19 '22 18:04 mjstelly

The fs.readFileSync() function can not be used with a directory in parameter. fs.readdirSync("D:\\Projects\\OGC\\assets\\Texture\\playingCards").forEach(file => {console.log(file);}); can be used to list all files in a directory or fs.readFileSync("D:\\Projects\\OGC\\assets\\favicon.ico").forEach(byte => {console.log(byte);}); to list all bytes of a file. but not a mix of both :)

xeuc avatar Dec 24 '22 12:12 xeuc