Coder Social home page Coder Social logo

Comments (12)

marco-elder avatar marco-elder commented on June 24, 2024

I can confirm that downgrading to ~14.1.0 or turning off turbopack works, as a workaround.

from next.js.

timneutkens avatar timneutkens commented on June 24, 2024

Sounds quite similar to #64520, can you try next@canary?

from next.js.

nphmuller avatar nphmuller commented on June 24, 2024

Just tried it, and it still reproduces on 14.3.0-canary.7. I updated the repro with this version.

from next.js.

nphmuller avatar nphmuller commented on June 24, 2024

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.

timneutkens avatar timneutkens commented on June 24, 2024

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.

nphmuller avatar nphmuller commented on June 24, 2024

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.

nphmuller avatar nphmuller commented on June 24, 2024

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.

nphmuller avatar nphmuller commented on June 24, 2024

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.

juanvilladev avatar juanvilladev commented on June 24, 2024

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.

jmikrut avatar jmikrut commented on June 24, 2024

Possibly related:
#64412

from next.js.

timneutkens avatar timneutkens commented on June 24, 2024

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.

github-actions avatar github-actions commented on June 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.