运行relay-compiler时遇GraphQL类型错误及Watchman路径问题求解决方案
Let’s tackle your problems one by one—first the Watchman warning (which is just a heads-up, not the root cause of your failure), then the critical type error that’s causing the exit code 100.
1. Resolving the Watchman Warning
That Watchman message is only a warning, not the reason your command failed. Here’s how to handle it:
- Option 1: Install Watchman: If you want to use Relay’s file-watching feature (for auto-recompiling when files change), install Watchman following the official installation steps for your OS.
- Option 2: Disable Watchman checks: If you don’t need watching right now, add the
--no-watchflag to your Relay command to skip Watchman entirely:relay-compiler --src ./src/client --schema schema.graphql --no-watch
2. Fixing the "Expected undefined to be a GraphQL leaf type" Error
This is the critical issue that’s making your command fail with exit code 100. It means your schema.graphql file contains a field with an invalid undefined type—GraphQL doesn’t recognize undefined as a valid leaf type (like String, Int, Boolean, ID, or custom scalars).
Here’s how to debug and fix it:
- Step 1: Audit your schema file: Open
schema.graphqland search for any occurrence ofundefined. You’ll likely find a line like:
This is invalid—replacesomeField: undefinedundefinedwith a valid GraphQL leaf type (e.g.,String,Int, or a custom scalar you’ve defined). - Step 2: Verify the source schema: The
undefinedtype probably came from your GraphQL server. Check if your server’s schema has a field with an unassigned or incorrectly resolved type. For example, maybe a resolver is returningundefinedinstead of a valid type, or the schema definition itself is missing a type declaration. - Step 3: Re-export the schema correctly: If
get-graphql-schemais causing the issue, try an alternative tool to export your schema. For example, usegraphql-cli(install it first withnpm install -g graphql-cli) and run:
Or copy the schema directly from your server’s GraphQL Playground (if available) to ensure accuracy.graphql get-schema --endpoint http://localhost/api/office --output schema.graphql - Step 4: Check for custom scalars: If you’re using custom scalars in your schema, make sure they’re properly defined in
schema.graphql(e.g.,scalar DateTime) and that Relay knows how to handle them (you may need to add scalar handling in your Relay configuration).
Once you’ve fixed the invalid undefined type in your schema, re-run the Relay compiler command—it should work without the exit code 100 error.
内容的提问来源于stack exchange,提问作者dprosper

