Coder Social home page Coder Social logo

Turbopack error on edge runtime(middleware): `Error [TypeError]: _react.default.createContext is not a function` about next.js HOT 12 CLOSED

chungweileong94 avatar chungweileong94 commented on June 17, 2024 2
Turbopack error on edge runtime(middleware): `Error [TypeError]: _react.default.createContext is not a function`

from next.js.

Comments (12)

fernandojbf avatar fernandojbf commented on June 17, 2024 1

@timneutkens using webpack, i continue to see the same issue:

image

from next.js.

jeslenbucci avatar jeslenbucci commented on June 17, 2024 1

This just began happening to me as well after upgrading to next@15 RC and adding middleware. I am not creating a context within the middleware. My context is in a client component with 'use client' at the top of the file. Everything was working fine, and still does, unless I add middleware.ts to the root of my src/ directory.

from next.js.

kyb3r avatar kyb3r commented on June 17, 2024

I'm having the same issue

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

from next.js.

fernandojbf avatar fernandojbf commented on June 17, 2024

In my project, the issue appears with Webpack using next-intl

from next.js.

OlegLustenko avatar OlegLustenko commented on June 17, 2024

the same issue

image

from next.js.

timneutkens avatar timneutkens commented on June 17, 2024

Please open a new issue with a reproduction. It's expected that createContext is not available in middleware / route handlers, they're bundled in the same way as server components nowadays to ensure that things like client-only / server-only work correctly.

from next.js.

jeslenbucci avatar jeslenbucci commented on June 17, 2024

For me, it appears this is an issue with AuthJS v5. If I remove authJS and throw in the middleware example found in the next docs (see below), the createContext is not a function log no longer appears.

My middleware without AuthJS (no error)

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
  return NextResponse.redirect(new URL('/sign-in', request.url))
}

// See "Matching Paths" below to learn more
export const config = {
  matcher: [
    '/dashboard/',
    '/account/:path*',
    '/dashboard/:path*',
    '/memberships/:path*',
    '/api/v2/:path*',
  ],
}

My middlewar with AuthJS (error)

export { auth as middleware } from '~/server/auth'

// See "Matching Paths" below to learn more
export const config = {
  matcher: [
    '/dashboard/',
    '/account/:path*',
    '/dashboard/:path*',
    '/memberships/:path*',
    '/api/v2/:path*',
  ],
}

from next.js.

fernandojbf avatar fernandojbf commented on June 17, 2024

Please open a new issue with a reproduction. It's expected that createContext is not available in middleware / route handlers, they're bundled in the same way as server components nowadays to ensure that things like client-only / server-only work correctly.

I can observe that i was using a dependency on the middleware that was using react context. removing that dependency made it working again Thanks

from next.js.

liuhuapiaoyuan avatar liuhuapiaoyuan commented on June 17, 2024

How to solve it in the end?

from next.js.

kyb3r avatar kyb3r commented on June 17, 2024

my issue is with authjs v5 as well, any workaround?

from next.js.

chungweileong94 avatar chungweileong94 commented on June 17, 2024

@liuhuapiaoyuan @kyb3r The latest canary version should resolved this. Fixed in https://github.com/vercel/next.js/releases/tag/v14.3.0-canary.81 to be specific.

from next.js.

timneutkens avatar timneutkens commented on June 17, 2024

As said above: please open a new issue with a reproduction.

Then we can have a look 🙂

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.