relay icon indicating copy to clipboard operation
relay copied to clipboard

relay-compiler tries to read directories

Open johntran opened this issue 9 years ago • 5 comments

Hi!

Ran

./node_modules/relay-compiler/bin/relay-compiler --schema ./schema.graphql -- src ./client --out ./client

Then I got

Error: EISDIR: illegal operation on a directory, read
    at Object.fs.readSync (fs.js:682:19)
    at tryReadSync (fs.js:480:20)
    at Object.fs.readFileSync (fs.js:517:19)
    at /Users/johntran/hopecommerce-proto/node_modules/relay-compiler/bin/relay-compiler:5713:40
    at /Users/johntran/hopecommerce-proto/node_modules/relay-compiler/bin/relay-compiler:5310:20
    at Array.forEach (native)
    at updateFiles (/Users/johntran/hopecommerce-proto/node_modules/relay-compiler/bin/relay-compiler:5306:16)
    at Object.<anonymous> (/Users/johntran/hopecommerce-proto/node_modules/relay-compiler/bin/relay-compiler:5188:13)
    at Generator.next (<anonymous>)
    at step (/Users/johntran/hopecommerce-proto/node_modules/relay-compiler/bin/relay-compiler:2994:31)

It errored on { name: 'onehopePackages', exists: true }

on this function in the relay-compiiler bin

function updateFiles(files, filter, fileChanges) {
	  var newFiles = new _set2['default'](files);
	  fileChanges.forEach(function (_ref) {
			console.log('_ref', _ref)
	    var name = _ref.name,
	        exists = _ref.exists;

	    if (exists && filter(name)) {
	      newFiles.add(name);
	    } else {
	      newFiles['delete'](name);
	    }
	  });
	  return newFiles;
	

Which is related to this line: https://github.com/facebook/relay/blob/3df7261b29fdca2922b3ffafbb09cc31ac053d42/packages/relay-compiler/codegen/RelayCodegenWatcher.js#L148

When working up the stack trace, I noticed that "expresssion" was undefined.

https://github.com/facebook/relay/blob/3df7261b29fdca2922b3ffafbb09cc31ac053d42/packages/relay-compiler/codegen/RelayCodegenWatcher.js#L29

When I modified the "queryFiles" function in RelayCodegenWatch with the following:

var expressionTwo = ['allof',
	 ['type', 'f'], 
	 ['suffix', 'js'], 
	 ['not', ['match', '**/__mocks__/**', 'wholename']], 
	 ['not', ['match', '**/__tests__/**', 'wholename']]
const resp = await client.command(
    'query',
    watchResp.root,
    makeQuery(watchResp.relativePath, expressionTwo)
  );

It worked.

Let me know if you need more information. Relay 2 is awesome btw.

johntran avatar Apr 16 '17 10:04 johntran

I think we would expect people to supply a watchman expression. We're probably missing some validation of the config that no required configs are missing.

kassens avatar Apr 16 '17 17:04 kassens

Yeah I just digged into the problem a little bit, when not using a .watchmanconfig it uses .git and thus, folders are reported in fileChanges here https://github.com/facebook/relay/blob/3df7261b29fdca2922b3ffafbb09cc31ac053d42/packages/relay-compiler/codegen/RelayCodegenWatcher.js#L154

chollier avatar Apr 16 '17 23:04 chollier

Not sure what is going on but I hit this issue and it was caused by parserConfigs.watchmanExpression being undefined. Looking at the source there is no way it is so it could be a bug with the build toolchain. Inlining WATCH_EXPRESSION in the function right before using it fixes the issue...

janicduplessis avatar Apr 17 '17 21:04 janicduplessis

Can confirm alpha 4 fixes this :)

johntran avatar Apr 18 '17 03:04 johntran

had this issue in ubuntu caused by next.js directory and fixed by changing directory name to nextjs!

RZsam avatar Oct 12 '20 15:10 RZsam