[GH-ISSUE #100] shadcn fail : React.createContext is not a function #27

Closed
opened 2026-05-06 12:36:37 +02:00 by BreizhHardware · 5 comments

Originally created by @liuhuapiaoyuan on GitHub (Feb 26, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/100

https://github.com/liuhuapiaoyuan/vinext-shadcn-bug

Image
Originally created by @liuhuapiaoyuan on GitHub (Feb 26, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/100 https://github.com/liuhuapiaoyuan/vinext-shadcn-bug <img width="616" height="446" alt="Image" src="https://github.com/user-attachments/assets/d66e16f8-6a86-41b8-936f-fddb5c72e4c5" />
Author
Owner

@beniaminrychter commented on GitHub (Feb 26, 2026):

I have the same issue. I use:

"radix-ui": "^1.4.3",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vinext": "^0.0.11",

Log

React.createContext is not a function
    at eval (/node_modules/.pnpm/@radix-ui+react-direction@1.1.1_@types+react@19.2.14_react@19.2.4/node_modules/@radix-ui/react-direction/src/direction.tsx:4:32)
    at async ESModulesEvaluator.runInlinedModule (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:913:3)
    at async ModuleRunner.directRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1146:59)
    at async ModuleRunner.cachedRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1053:73)
    at async eval (/node_modules/.pnpm/radix-ui@1.4.3_@types+react-dom@19.2.3_@types+react@19.2.14__@types+react@19.2.14_react_8630af8f756c6a5269f4297295494860/node_modules/radix-ui/src/index.ts:10:1)
    at async ESModulesEvaluator.runInlinedModule (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:913:3)
    at async ModuleRunner.directRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1146:59)
    at async ModuleRunner.cachedRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1053:73)
    at async eval (components/ui/button.tsx:3:1)
    at async ESModulesEvaluator.runInlinedModule (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:913:3)
<!-- gh-comment-id:3966456942 --> @beniaminrychter commented on GitHub (Feb 26, 2026): I have the same issue. I use: ``` "radix-ui": "^1.4.3", "react": "^19.2.4", "react-dom": "^19.2.4", "vinext": "^0.0.11", ``` ### Log ``` React.createContext is not a function at eval (/node_modules/.pnpm/@radix-ui+react-direction@1.1.1_@types+react@19.2.14_react@19.2.4/node_modules/@radix-ui/react-direction/src/direction.tsx:4:32) at async ESModulesEvaluator.runInlinedModule (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:913:3) at async ModuleRunner.directRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1146:59) at async ModuleRunner.cachedRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1053:73) at async eval (/node_modules/.pnpm/radix-ui@1.4.3_@types+react-dom@19.2.3_@types+react@19.2.14__@types+react@19.2.14_react_8630af8f756c6a5269f4297295494860/node_modules/radix-ui/src/index.ts:10:1) at async ESModulesEvaluator.runInlinedModule (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:913:3) at async ModuleRunner.directRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1146:59) at async ModuleRunner.cachedRequest (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:1053:73) at async eval (components/ui/button.tsx:3:1) at async ESModulesEvaluator.runInlinedModule (file:///node_modules/.pnpm/vite@7.3.1_@types+node@22.19.12_jiti@2.6.1_lightningcss@1.31.1_terser@5.46.0/node_modules/vite/dist/node/module-runner.js:913:3) ```
Author
Owner

@sanwalsulehri commented on GitHub (Feb 26, 2026):

can i work on this

<!-- gh-comment-id:3968503641 --> @sanwalsulehri commented on GitHub (Feb 26, 2026): can i work on this
Author
Owner

@sanwalsulehri commented on GitHub (Feb 26, 2026):

can i work on this

<!-- gh-comment-id:3968505221 --> @sanwalsulehri commented on GitHub (Feb 26, 2026): can i work on this
Author
Owner

@southpolesteve commented on GitHub (Mar 1, 2026):

Investigated this. The standard ShadCN setup with individual @radix-ui/* packages works correctly with vinext, including:

  • Button (server component, no "use client") using @radix-ui/react-slot
  • Dialog ("use client") using @radix-ui/react-dialog
  • DropdownMenu ("use client") using @radix-ui/react-dropdown-menu

The reason it works: the individual @radix-ui/* packages that use client-only React APIs (createContext, hooks, etc.) properly declare "use client" in their published dist files. The RSC plugin intercepts these and creates client reference proxies, so the actual code never executes in the RSC environment. Packages like @radix-ui/react-slot that don't use client-only APIs work fine as server components.

Root cause of the reported error: The reproduction repo uses the unified radix-ui package (v1.x), which barrels all Radix primitives into a single entry point. That barrel file does not have "use client" at the top, so when it gets loaded in the RSC environment, it pulls in modules like @radix-ui/react-direction that call React.createContext() at the top level. In the RSC environment, react resolves to react-server, which doesn't export createContext.

Workaround: Use the individual @radix-ui/* packages (which is what ShadCN's CLI generates by default) instead of the unified radix-ui package.

Added ecosystem coverage for ShadCN/Radix UI to the test suite so we don't regress on this.

<!-- gh-comment-id:3979919512 --> @southpolesteve commented on GitHub (Mar 1, 2026): Investigated this. The standard ShadCN setup with individual `@radix-ui/*` packages works correctly with vinext, including: - **Button** (server component, no `"use client"`) using `@radix-ui/react-slot` - **Dialog** (`"use client"`) using `@radix-ui/react-dialog` - **DropdownMenu** (`"use client"`) using `@radix-ui/react-dropdown-menu` The reason it works: the individual `@radix-ui/*` packages that use client-only React APIs (`createContext`, hooks, etc.) properly declare `"use client"` in their published dist files. The RSC plugin intercepts these and creates client reference proxies, so the actual code never executes in the RSC environment. Packages like `@radix-ui/react-slot` that don't use client-only APIs work fine as server components. **Root cause of the reported error:** The reproduction repo uses the unified `radix-ui` package (v1.x), which barrels all Radix primitives into a single entry point. That barrel file does not have `"use client"` at the top, so when it gets loaded in the RSC environment, it pulls in modules like `@radix-ui/react-direction` that call `React.createContext()` at the top level. In the RSC environment, `react` resolves to `react-server`, which doesn't export `createContext`. **Workaround:** Use the individual `@radix-ui/*` packages (which is what ShadCN's CLI generates by default) instead of the unified `radix-ui` package. Added ecosystem coverage for ShadCN/Radix UI to the test suite so we don't regress on this.
Author
Owner

@liuhuapiaoyuan commented on GitHub (Mar 2, 2026):

👏👏👏👏👏👏👏👏👏👏👏👏👏👏
Perfect fix, I changed the repository name vinext-shadcn-starter

<!-- gh-comment-id:3981971755 --> @liuhuapiaoyuan commented on GitHub (Mar 2, 2026): 👏👏👏👏👏👏👏👏👏👏👏👏👏👏 Perfect fix, I changed the repository name [vinext-shadcn-starter]( https://github.com/liuhuapiaoyuan/vinext-shadcn-starter)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#27
No description provided.