Comments (12)
I can confirm that downgrading to ~14.1.0
or turning off turbopack works, as a workaround.
from next.js.
Sounds quite similar to #64520, can you try next@canary?
from next.js.
Just tried it, and it still reproduces on 14.3.0-canary.7. I updated the repro with this version.
from next.js.
Looking at the issue you linked I can see why it sounds similar. Here's some additional details which hopefully help:
I'm not directly importing a client component (that uses createContext), I'm import the env
function from this file: https://github.com/expatfile/next-runtime-env/blob/development/src/script/env.ts
The function is re-exported via an index.ts file (https://github.com/expatfile/next-runtime-env/blob/development/src/index.ts) and that file does import the code that eventually calls createContext. That code is not directly used by me.
The index.ts file contains:
export * from './provider';
which imports/exports https://github.com/expatfile/next-runtime-env/blob/development/src/provider/env-context.ts which contains the createContext() call.
from next.js.
Ah I see, that's a bug in that particular library, it was a bug in Next.js that this previously didn't fail so now it's highlighting problems in libraries that are being used in Route Handlers, as Route Handlers run in the same layer as server components basically.
What needs to change in that library is that it should add "use client"
to this file: https://github.com/expatfile/next-runtime-env/blob/development/src/provider/env-context.ts
from next.js.
Okay, thank you. I’ll open up a PR. Just to double check: I don’t get this error when I run ‘npm run dev’ without turbo. Does that mean this bug hasn’t been fixed in the non turbo dev build?
from next.js.
I just forked the project and added 'use client' to that file, and the issue still occurs. I'll double check and update the repro in a minute.
Edit: After checking the code more thoroughly: env-context.tsx was only exposed via an import in env-provider.tsx, and env-provider.tsx already contained 'use client'. I still added 'use client' to env-context.tsx, just in case to test it. But the issue still occurred.
from next.js.
I've published the change here (on my fork): https://github.com/nphmuller/next-runtime-env/commits/fix-next-turbo-compat/
I've also published this version as @nph.muller/next-runtime-env (version 0.0.4) on npm, and updated the repro in the original post to use my fork.
from next.js.
Having this same issue on 14.2.2.
Using --turbo leads to
⨯ createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component
from next.js.
Possibly related:
#64412
from next.js.
Verified this is fixed on next@canary, similar issue to #64412 indeed.
Sandbox: https://codesandbox.io/p/github/nphmuller/next-14-2-turbo-api-routes-repro/csb-ctxpvy/draft/inspiring-mclaren?file=%2Fapp%2Fapi%2Froute.ts%3A7%2C1
Url: https://ctxpvy-3000.csb.app/api
from next.js.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
from next.js.
Related Issues (20)
- `router.replace()` on pages with query params cause entire page re-render on Next 14.2.3 HOT 1
- Form state not updating and suspended components reloading on first server action submission when using revalidatePath with loading.tsx in app router HOT 1
- `router.replace()` on pages with query params cause entire page re-render on Next 14.2.3 HOT 1
- Suspense boundary broken (ignored) after second server action call HOT 8
- Nonce exposed to the DOM
- [Bug][Next.js13]: renderError does not follow the err info of __NEXT_DATA__ when hytrate in client
- Docs: Wrong link for UseFormState. HOT 3
- `no-store` cache in nextjs config doesn't disable disk caching.
- The `maxDuration` setting in the api route config, as per the documentation, isn't being honored on dev or on Vercel. We're on the pro plan. HOT 1
- TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner') when rendering model using react-three libraries HOT 1
- next/og don't work when turbo is enabled in dev HOT 1
- Metadata is not generated for intercepting routes HOT 1
- Monorepo self-referencing package imports don't resolve in certain cases with Turbopack
- Creating instance of URL with basePath gets mangled HOT 1
- Creating instance of URL with basePath gets mangled
- Regression since `v14.2.0-canary.24`: `loading.tsx` triggered on first `revalidatePath()` call HOT 2
- Nested parallel routes slot rendered after navigating back HOT 3
- graphql-request and caching HOT 4
- Client side navigation not working properly in latest next@rc for dev HOT 1
- Intercepted route not generating metadata
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.