facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.37k stars 1.82k forks source link

Relay compiler fails with "EISDIR: illegal operation on a directory, read" on directories with a dot #3572

Open christianvuerings opened 3 years ago

christianvuerings commented 3 years ago

Repro Steps

  1. Create a JS file in a directory with a . dot in it. Example: routes/advertiser/[aid]/quick-promote.js/quick-promote.a11y.js
  2. Run relay-compiler
  3. Output:
[Error] ERROR:
[Error] EISDIR: illegal operation on a directory, read
[Error] From: CodegenRunner.compileAll
[Error] at Object.readSync (fs.js:592:3)
[Error] at tryReadSync (fs.js:366:20)
[Error] at Object.readFileSync (fs.js:403:19)
[Error] at hashFile (/home/cvuerings/code/pinboard/webapp/node_modules/relay-compiler/bin/relay-compiler:9179:20)
[Error] at /home/cvuerings/code/pinboard/webapp/node_modules/relay-compiler/bin/relay-compiler:9159:23
[Error] at Array.forEach (<anonymous>)
[Error] at updateFiles (/home/cvuerings/code/pinboard/webapp/node_modules/relay-compiler/bin/relay-compiler:9149:15)
[Error] at Object.<anonymous> (/home/cvuerings/code/pinboard/webapp/node_modules/relay-compiler/bin/relay-compiler:9031:12)
[Error] at Generator.next (<anonymous>)
[Error] at asyncGeneratorStep (/home/cvuerings/code/pinboard/webapp/node_modules/relay-compiler/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
[Error] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Issue

hashFile receives a directory as the filename argument: routes/advertiser/[aid]/quick-promote.js and tries to do an fs.readFileSync on it.

https://github.com/facebook/relay/blob/86842c141eb59b31269893f224bf24375a2b3539/packages/relay-compiler/codegen/CodegenWatcher.js#L239-L240

christianvuerings commented 3 years ago

Another case of this was reported in https://github.com/facebook/relay/issues/1613#issuecomment-707187979

kassens commented 3 years ago

Actually, I think this breaks watch mode when files are deleted. I'd not risk new breakage (since internal usage of the JS based compiler is pretty minimal by now, so we have less coverage for breakages).

Maybe you can change the directory name? I suspect it's some directory ending in .js maybe?

christianvuerings commented 3 years ago

@kassens thanks for taking a look. We use file based routing at Pinterest which means we can't update the directory name.

Right now, we use a forked version of the relay compiler: https://registry.npmjs.org/@christianv/relay-compiler/

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.