graphiql: [graphiql] v5 stopped working with react-router + vite (ssr)
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
Dev command failure:
pnpm dev
> graphiql-issue-4038@1.0.0 dev /Users/AndKiel/graphiql-issue-4038
> react-router dev
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
➜ press h + enter to show help
8:33:24 AM [vite] (ssr) Error when evaluating SSR module virtual:react-router/server-build: Cannot find package '/Users/AndKiel/graphiql-issue-4038/node_modules/.pnpm/@graphiql+react@0.35.1_@emotion+is-prop-valid@1.3.1_@types+node@22.15.34_@types+react-d_ab41ef91f1590d5987c2e54135e53055/node_modules/monaco-editor/index.js' imported from /Users/AndKiel/graphiql-issue-4038/node_modules/.pnpm/@graphiql+react@0.35.1_@emotion+is-prop-valid@1.3.1_@types+node@22.15.34_@types+react-d_ab41ef91f1590d5987c2e54135e53055/node_modules/@graphiql/react/dist/constants.js
Start command failure from built assets:
pnpm build
pnpm start
Error: Cannot find package '/Users/AndKiel/graphiql-issue-4038/node_modules/.pnpm/@graphiql+react@0.35.4_@emotion+is-prop-valid@1.3.1_@types+node@22.15.34_@types+react-d_eacbdec10b067bb210951a38e2120f2e/node_modules/monaco-editor/index.js' imported from /Users/AndKiel/graphiql-issue-4038/node_modules/.pnpm/@graphiql+react@0.35.4_@emotion+is-prop-valid@1.3.1_@types+node@22.15.34_@types+react-d_eacbdec10b067bb210951a38e2120f2e/node_modules/@graphiql/react/dist/constants.js
My project uses ssr: true react-router config. Previous versions work fine when they are only rendered client-side. Version 5 doesn’t work regardless of forcing rendering only client-side.
Expected Behavior
App to build and start without errors.
Steps To Reproduce
Minimal reproduction: https://github.com/AndKiel/graphiql-issue-4038
Environment
- GraphiQL Version: latest (v5)
Anything else?
The issue is created/extracted from: https://github.com/graphql/graphiql/issues/4038
I’ve had no issues with the graphiql versions 1-4, including SSR (server-side rendering). The problem started with version 5 and the switch to monaco-editor. Reproduction working when downgraded to v4:
https://github.com/AndKiel/graphiql-issue-4038/commit/323b17960b457a385bfb6a395e413fcc0a72ea23
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 25 (2 by maintainers)
@dimaMachina, thank you. I was able to upgrade my project, and everything works as expected. No issues with editor states or worker setup (newly provided esm.sh variant by graphiql), dev mode works, built app works, and the upgrade process for react-router became straightforward and effortless.
@AndKiel new example was added https://github.com/graphql/graphiql/tree/main/examples/graphiql-vite-react-router
and bug in
useOperationsEditorStateanduseVariablesEditorStatewere fixed in graphiql 5.1@AndKiel @AaronMoat docs for React router usage were updated https://github.com/graphql/graphiql/blob/main/packages/graphiql/README.md#usage-with-react-router-and-ssr-true