Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve turbopack regression #627

Merged
merged 1 commit into from
Mar 7, 2024
Merged

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Mar 7, 2024

The fix for Nuxt (#625) broke Next with Turbopack again (#606).

The last reproduction was a false positive..
The Turbopack issue happens whenever a client component imports an @sanity/client instance.

next dev --turbo
   ▲ Next.js 14.1.3 (turbo)
   - Local:        http://localhost:3000

 ✓ Ready in 886ms
 ○ Compiling / ...
 ✓ Compiled / in 5.1s

 ⨯ app/sanity.ts (3:13) @ <unknown>
 ⨯ TypeError: __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2d$sanity$2f$node_modules$2f40$sanity$2f$client$2f$dist$2f$index$2e$cjs$2e$js__$5b$app$2d$ssr$5d$__$28$ecmascript$29$__.createClient is not a function
    at /workspace/.next/server/chunks/app_7485fc._.js:12:220
    at [project]/app/sanity.ts [app-ssr] (ecmascript) (/workspace/.next/server/chunks/app_7485fc._.js:19:3)
    at instantiateModule (/workspace/.next/server/chunks/[turbopack]_runtime.js:488:23)
    at getOrInstantiateModuleFromParent (/workspace/.next/server/chunks/[turbopack]_runtime.js:539:12)
    at esmImport (/workspace/.next/server/chunks/[turbopack]_runtime.js:113:20)
    at /workspace/.next/server/chunks/app_7485fc._.js:29:117
    at [project]/app/page.client.tsx [app-ssr] (ecmascript) (/workspace/.next/server/chunks/app_7485fc._.js:56:3)
    at instantiateModule (/workspace/.next/server/chunks/[turbopack]_runtime.js:488:23)
    at getOrInstantiateModuleFromParent (/workspace/.next/server/chunks/[turbopack]_runtime.js:539:12)
    at commonJsRequire (/workspace/.next/server/chunks/[turbopack]_runtime.js:127:20)
  1 | import { createClient } from "next-sanity";
  2 |
> 3 | export const client = createClient({
    |             ^
  4 |   projectId: "hiomol4a",
  5 |   dataset: "development",
  6 |   apiVersion: "2024-03-07",

The fix is to remove the node.import re-export wrapper pattern completely. Testing a canary of this PR solves the repro..
It doesn't cause regressions in Node runtimes. Moving forward it seems we need to end the Dual Package Hazard patterns for compatibility with the npm ecosystem of frameworks and runtimes.

@stipsan stipsan merged commit fdb999a into main Mar 7, 2024
15 checks passed
@stipsan stipsan deleted the fix-turbopack-regression branch March 7, 2024 18:22
@ecospark ecospark bot mentioned this pull request Mar 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant