Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[NextJS 14.1.0] TypeError: Cannot read properties of undefined (reading 'call') #61995

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

Open
dashawk opened this issue Feb 13, 2024 · 26 comments
Open
Labels
bug Issue was opened via the bug report template. Lazy Loading Related to Next.js Lazy Loading (e.g., next/dynamic or React.lazy). Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Module Resolution Module resolution (CJS / ESM, module resolving). Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@dashawk
Copy link

dashawk commented Feb 13, 2024

Link to the code that reproduces this issue

https://github.com/dashawk/nextjs-14-bugger

To Reproduce

Current vs. Expected behavior

After doing all the reproduction steps, you will see the error. As you can see, I have already applied the suggested fix for [email protected]
image

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
Binaries:
  Node: 20.11.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Data fetching (gS(S)P, getInitialProps), Dynamic imports (next/dynamic), Metadata (metadata, generateMetadata, next/head), Middleware / Edge (API routes, runtime), Module resolution (CJS / ESM, module resolving), Routing (next/router, next/navigation, next/link)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I have encountered this issue only in [email protected] which is giving me a headache.

_

Upgrading might not be a very good habit.

_

@dashawk dashawk added the bug Issue was opened via the bug report template. label Feb 13, 2024
@github-actions github-actions bot added Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js. Module Resolution Module resolution (CJS / ESM, module resolving). Lazy Loading Related to Next.js Lazy Loading (e.g., next/dynamic or React.lazy). Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. labels Feb 13, 2024
@icyJoseph
Copy link
Contributor

Hi,

I can't really reproduce... https://stackblitz.com/edit/github-zj7avh?file=src%2Fapp%2Fpage.tsx

I wonder if the problem is within your OS or Node.js version?

If you run node -e "console.log(process.arch)" does that match your OS architecture?

@dashawk
Copy link
Author

dashawk commented Feb 13, 2024

It does match my OS
image
image

Is it possible that this is just a cache issue?

@icyJoseph
Copy link
Contributor

Alright, could you try with a Node version in the 18 range? Say 18.18.0?

Clean up all of the node_modules and lock file too.

@dashawk
Copy link
Author

dashawk commented Feb 13, 2024

Here is what I did just now.

I still use the node version v20.11.0

Step I did try

# Clean up the cache
npm cache clean --force

# Delete yarn.lock
rm yarn.lock

# Run dev again
yarn dev

I did not see the TypeError anymore. For some reason it fixes the issue. I cannot determine what caused the issue though.

@dashawk
Copy link
Author

dashawk commented Feb 13, 2024

Here is what I did just now.

I still use the node version v20.11.0

Step I did try

# Clean up the cache
npm cache clean --force

# Delete yarn.lock
rm yarn.lock

# Run dev again
yarn dev

I did not see the TypeError anymore. For some reason it fixes the issue. I cannot determine what caused the issue though.

Though this steps did not fix my other project with the same setup.

Here is the other project that I am talking about.
https://github.com/dashawk/swertres-app

I have tried

I have already tried clearing out the node_modules and the lock files and did a new yarn install using node v18.17.0 but it is still the same thing happening.

@narasimhajupally
Copy link

facing the same issue during HMR and navigation when using npm run dev
doing ctrl+shift+r (hard reload) removes the error and renders the page correctly but again when a file is changed and HMR is triggered resulting in the same error.
using node lts : 20.11.1

@narasimhajupally
Copy link

narasimhajupally commented Feb 19, 2024

ok when I killed npm run dev and reloaded the localhost the page was still rendered. From the network tab, I got to know the page was being fetched from a service worker so I unregistered it and the problem is gone

@dashawk
Copy link
Author

dashawk commented Feb 20, 2024

ok when I killed npm run dev and reloaded the localhost the page was still rendered. From the network tab, I got to know the page was being fetched from a service worker so I unregistered it and the problem is gone

Is there a way that we can disable this feature? It is probably like a caching issue.

@narasimhajupally
Copy link

I think the service worker gets registered when you do npm run start and open localhost:3000. So, for previewing the prod build run on a different port or open in incognito, guessing.

@fstovarr
Copy link

I am getting TypeError: Cannot read properties of undefined (reading 'call') after introducing a very basic middleware.
It works well on my local but the error appears after deploying to a preview env in Vercel.

[GET] [middleware: "src/middleware"] /exhibitions/{***}/{***} reason=EDGE_FUNCTION_INVOCATION_FAILED, status=500, user_error=true

TypeError: Cannot read properties of undefined (reading 'call')

It happens on Nextj14.
Current version: 14.2.2

My middleware:

import {NextResponse} from 'next/server'

export function middleware() {
  return NextResponse.next()
}

export const config = {
  matcher: '/exhibitions/:path+',
}

@huilensolis
Copy link

huilensolis commented May 17, 2024

I'm facing the same error with the app router.

I'm calling a function from a client component, then redirecting to a route which is intercepted by a middleware.ts.
I have used many server actions in my application that work fine, but this one doesn't, and idk why.

in development mode, I get:

⨯ TypeError: __webpack_modules__[moduleId] is not a function
    at Object.__webpack_require__ [as require] (/.next/server/webpack-runtime.js:33:42)

and in production mode, I get:

TypeError: Cannot read properties of undefined (reading 'call')
    at Object.t [as require] (/home/huilensolis/dev/projects/Pictura/.next/server/webpack-runtime.js:1:143)
    at /home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:473
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async rc (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:14:5243)
    at async rj (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:22333)
    at async doRender (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1406:30)
    at async cacheEntry.responseCache.get.routeKind (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1567:28)
    at async NextNodeServer.renderToResponseWithComponentsImpl (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1475:28)
    at async NextNodeServer.renderPageComponent (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1852:24)
    at async NextNodeServer.renderToResponseImpl (/home/huilensolis/dev/projects/Pictura/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1890:32)

my node version:

> node -v
v18.18.0

my node architecture:

> node -e "console.log(process.arch)"
x64

my os architecture:

Linux 6.8.2-arch2- x86_64 GNU/Linux

@dashawk

This comment has been minimized.

@murphpdx
Copy link

murphpdx commented Jun 18, 2024

We're facing the same issue in production. We are hosted on vercel. I believe it's building with Node version 20.11.0 and Detected Next.js version: 14.0.3.

This error is happening pretty often and slowing down our page load.

I attempted running the app in production with node version 18 and I'm still seeing the error.

@JClackett
Copy link
Contributor

Having this a lot in production as well, 14.2.3, node 20.

Cannot read properties of undefined (reading 'call')

Chrome 126.0.0
Windows >=10

Server action to login in a user, basic form that takes email and password

@marcoswebmasteroficial
Copy link

I'm having the same problem, nextjs 14.2.15, node 20.15.0

@Ammar-kutubee
Copy link

I'm having the same problem, nextjs 14.2.15 ( i tries all versions from 14.2.1 => 14.2.15), node v20.16 LTS IRON

@Ammar-kutubee
Copy link

facing the same issue during HMR and navigation when using npm run dev doing ctrl+shift+r (hard reload) removes the error and renders the page correctly but again when a file is changed and HMR is triggered resulting in the same error. using node lts : 20.11.1

this worked but i cant force my clients to do so , also NODE_ENV=production sort of helped (reduced frequency of occurrence smh)

@redbmk
Copy link
Contributor

redbmk commented Oct 31, 2024

Could this have something to do with version skew? I have a setup that allows me to deploy two separate versions at a time and pick which one I want based on a cookie to test what would happen for users after deploying a new version.

What I've noticed is if I am on one version of the app and then switch the cookie to the other version, then navigation seems to work fine, but server actions cause this error to occur.

I'm trying to track down if it's for all server actions or maybe specific to ones that redirect or revalidate or something.

For the record, this is on 14.2.4.

image

The component stack doesn't seem terribly useful as it's all minified code, but it looks something like:

at Lazy
at div
at div
at C (reference to line in minified chunk)
at c ... etc with a bunch of single letters, presumably custom components
...
at body
at html
at s ... more single letters
...

@redbmk
Copy link
Contributor

redbmk commented Oct 31, 2024

OK, I was able to work around this. When I detect that app versions are different and I get a request with accept: text/x-component I can force the response to be something else (e.g. text/plain). This tells the frontend that something is amiss and it should do an MPA navigation.

From what I understand, NextJS has built-in skew protection like this starting in 14.2.7: #67255

I'll have to play around with it because I don't really see it documented very well unless I'm missing something. But it's unclear to me if this would only work if the client is already on at least 14.2.7, or if the server responds with something that can trigger older versions to treat it as an MPA (like the text/plain mentioned above). It's also unclear if you need to set a NEXT_DEPLOYMENT_ID variable at runtime or build time, or if you need to set it as an option in your next.config.js (Based on the name I suspect a runtime variable would make the most sense). Most of the docs I'm finding are specific to Vercel's Skew Protection, which looks pretty similar.

@JClackett
Copy link
Contributor

Still getting this in production, assuming it's due to version skew? but as @redbmk suggested, nextjs has something built in? it definitely seems to be around when new versions get deployed, but im not sure how to fix this if next.js skew protection isnt working for me

using "next": "14.2.16" + react 18

@asifrahmanvm
Copy link

asifrahmanvm commented Jan 30, 2025

I had a library in my package.json and was also dynamically loading the same library but with a different version, which was causing the issue. https://vercel.com/docs/deployments/skew-protection

The solution was to sync the versions of the npm package and the dynamically loaded script.

@arduano
Copy link

arduano commented Jan 30, 2025

I'm on deno and I seem to reliably get this server-side when I update any module. Then doing a reset and a git clean persists the issue. No idea what causes it, and my solution have been going back and forth between versions for an hour or two until something works again.

@redbmk
Copy link
Contributor

redbmk commented Feb 24, 2025

I had a hard time getting the built-in skew protection to work. It seems like NEXT_DEPLOYMENT_ID needs to be set at build time, rather than deployment time, which made it harder for me to use because it acted as a cache bust. Maybe not a big deal when making changes to the app, but for any cicd changes or other unrelated changes in a monorepo, it meant the docker build could never be cached.

I tried making the deployment ID something like XXX_DEPLOYMENT_ID_XXX and replacing all instances of it in the code before starting the app but I must have missed something because that didn't seem to catch it everywhere. I ended up putting an nginx service in front of nextjs just to use the text/plain hack I mentioned above, which works pre-14.2.7 as well, but ideally I don't need another server in front of Next.

It seems like middleware would be a decent place to force MPA instead of RSC based on a cookie (e.g. app_version or deploy_id) but I wasn't able to get this to work. I might take another stab at it here soon, but if anyone has any ideas I'm all ears. Would be great to get rid of nginx if this was the only thing I needed it for

@aamorozov
Copy link

It happened a few times locally while recording network requests and starting/stopping the service multiple times for me

@FlyingGrasss
Copy link

I am having the same error but instead with 'exec',

TypeError: Cannot read properties of undefined (reading 'exec')

does anybody know a fix for this?

@FabioDiCeglie
Copy link

Having same issue with NextJS `` "next": "15.2.4"```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Lazy Loading Related to Next.js Lazy Loading (e.g., next/dynamic or React.lazy). Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Module Resolution Module resolution (CJS / ESM, module resolving). Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests