21

I'm pretty new to Next.js and Typescript. I wanna build a project using next.js and typescript and tailwind CSS using this simple create app command: npx create-next-app -e with-tailwindcss my-project

Everything just went fine until I wanted to use the Image tag using next/image and got an error

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

Call Stack
options.factory
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/webpack.js (710:31)
__webpack_require__
/_next/static/chunks/webpack.js (37:33)
fn
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/webpack.js (365:21)
require
node_modules\next\dist\client\image.js (7:15)
./node_modules/next/dist/client/image.js
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/app/layout.js (39:1)
options.factory
/_next/static/chunks/webpack.js (710:31)
__webpack_require__
file:///C:/Users/irwan/Projects/messenger-clone/meta-messenger/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (365:21)
__webpack_require__
node_modules\next\dist\client\app-index.js (26:16)
requireModule
node_modules\next\dist\compiled\react-server-dom-webpack\client.js (142:0)
initializeModuleChunk
node_modules\next\dist\compiled\react-server-dom-webpack\client.js (427:0)
resolveModuleChunk
node_modules\next\dist\compiled\react-server-dom-webpack\client.js (385:0)
eval
node_modules\next\dist\compiled\react-server-dom-webpack\client.js (668:0)

I'm sure the error is not about the URL as I already added the domain to be whitelisted in my next.config.js file.

Here is my package JSON file:

{
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "^13.0.7",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@types/node": "18.11.3",
    "@types/react": "18.0.21",
    "@types/react-dom": "18.0.6",
    "autoprefixer": "^10.4.12",
    "postcss": "^8.4.18",
    "tailwindcss": "^3.2.1",
    "typescript": "^4.8.4"
  }
}

Last I'm using the beta feature(?) appDir on next.js 13. Here is my next.config.js file:

reactStrictMode: true,
  images: {
    domains: ['i.ibb.co']
  },
  experimental: {
    appDir: true
  }

I'm using the image tag on my Header.tsx component. Here is my Header.tsx

import Image from "next/image";
import React from "react";

function Header() {
  const url = "https://i.ibb.co/LhMfkJw/logo-Meta.png";
  return (
    <header>
      <div>
        <div>
          <Image src={url} alt="Logo" width={50} height={10} />
        </div>
      </div>
    </header>
  );
}

export default Header;

And then use that header on my layout.tsx component:

import "../styles/globals.css";
import Header from "./Header";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html>
      <head />
      <body>
        <Header />
        {children}
      </body>
    </html>
  );
}

Thanks for the reply

6
  • 1
    Hi, welcome to Stack Overflow. Please include all the relevant code so we can assist you. Where are you using the Image component? Commented Dec 17, 2022 at 6:47
  • Hi @ivanatias, thanks for the reply. I'm adding relevant detail now on my thread. Commented Dec 17, 2022 at 7:20
  • Could you try to download the image and use the downloaded image instead of a link? Commented Dec 17, 2022 at 9:55
  • 1
    Hi. @Likepineapple I did try but it still threw the same error. Commented Dec 17, 2022 at 10:08
  • Can you create a GitHub repo with the code? Commented Dec 17, 2022 at 10:20

10 Answers 10

16

Remove all the service workers.

DevTools > Application > Storage > Clear site data

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Could you explain this a bit more? Why does this fix it? I wouldn't expect users to do this normally... is this something that only happens in dev?
10

I also had this same problem please change ur next version to 13.0.6 and wait until we all get 13.0.8 or greater than that it is a problem in version 13.0.7

7 Comments

Still having this issue with version 13.0.6
please delete your .next folder and node_modules folder and run npm i and try again @NeuTronas
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This comment is True. i reverted back from 13.0.7 to 13.0.6 and that same error was gone.
I also have this issue with version 14.0.3
|
7

For those using next-transpile-modules — use transpilePackages option instead. This will resolve the issue for you.

The npm page says that this package is built-in in next 13.1 https://www.npmjs.com/package/next-transpile-modules

3 Comments

This fixed my issue, for those who are looking how to to use new prop, here is a link nextjs.org/docs/advanced-features/compiler#module-transpilation
this also fixed my isssue, which in my case was showing TypeError: Cannot read properties of undefined (reading 'and')
Plus 1 this also helped me fix TypeError: Cannot read properties of undefined (reading 'and') thanks!
3

I'm not sure exactly what causes this, but doing an npm install next@canary solved this issue for me

1 Comment

Thankss, will be trying it.
1

go to page.tsx or page.js and delete all Image components and everything will work fine Edit#1 Use this command; it will fix that issue: npm install next@canary next@canary is a next.js package that fixes issues and problems before moving on to the next.js version

3 Comments

:/ but how will we use Image component then?
at this point use (npm install next@canary) that will fix you issues
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1

I finally have some time to continue this project and as @Abdelrhman kamal mentioned that the usage of next/image can be solved by installing next canary:

npm install next@canary

May be it is already fixed in the update released as I previously use next version of 13.0.7 and the canary one is 13.1.1.

Thanks

Comments

1

This might be an issue with the internal SSR (server and client components) of Next 13. Try changing your client component from import to const Components = dynamic(() => import("."), {ssr: false})

Comments

0

I think this problem will have various triggers and various solutions, but this is one solution for one context: intercepting routes.

The issue exists in Next.js 15 (every version I've tested) and React 19 (every version I've tested), and likely earlier versions, when bundled with Webpack (the default in dev, and only option when hosted on Vercel, at the time of writing). The problem does not exist when bundled with Turbopack (next dev --turbo) but that's not helpful if deploying to Vercel, until Turbopack is deemed stable for production.

You won't see the problem with this directory structure:

@modal
 - (.)dirName
   - page.tsx
 - error.tsx
 - loading.tsx

But, you will see the issue as soon as you try to intercept a route at a higher level (note .. instead of .):

@modal
 - (..)dirName
   - page.tsx
 - error.tsx
 - loading.tsx

The bug is actually triggered by the special files. Moving them into the intercept directory fixes the issue.

@modal
 - (..)dirName
   - page.tsx
   - error.tsx
   - loading.tsx

Comments

-1

I am not sure what the exact updates are. but yarn add next@canary or npm install next@canary worked for me. More information:

https://github.com/vercel/next.js/blob/canary/docs/upgrading.md

Comments

-1

I solved this by changing my dev start command from next dev to next dev --turbo. Note that this only works on Next.js 14

Edit: this happened again and I was able to resolve the issue by unregistering the service worker I had on my website through the chrome devtools and then hard reloading the page.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.