#Cannot find module 'next/router' or its corresponding type declarations.

26 messages · Page 1 of 1 (latest)

rugged sierra
#
import { useRouter } from 'next/router';
// Cannot find module 'next/router' or its corresponding type declarations.
{
  "name": "site",
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "lint": "next lint",
    "start": "next start"
  },
  "dependencies": {
    "@trpc/next": "^10.19.1",
    "next": "13.3.0",
    "next-auth": "^4.15.0",

I have ran "yarn" to install everything, but it still shows this error, even after restarting the TS server. Not sure what's wrong?

#

I also have types/next installed as a dev dependency

  "devDependencies": {
    "@types/next": "^9.0.0"
  }
#

This is actually the same for all next imports..
import Link from 'next/link';
import Image from 'next/image';

zenith fog
#

Just uninstall and it should work.

#

Next provides it's own type definitions, so you don't need @types/next

rugged sierra
#

thank you 🙂

#

hm, unfortunately this has not resolved the problem

#

It is still a problem with all nextjs imports

I have removed "@types/next": "^9.0.0" as a dependency and ran yarn again

#
{
  "name": "site",
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "lint": "next lint",
    "start": "next start"
  },
  "dependencies": {
    "@trpc/next": "^10.19.1",
    "next": "13.3.0",
    "next-auth": "^4.15.0",
    "@emotion/react": "^11.10.4",
    "@emotion/server": "^11.10.0",
    "@mantine/carousel": "^6.0.6",
    "@mantine/core": "^6.0.6",
    "@mantine/form": "^6.0.6",
    "@mantine/hooks": "^6.0.6",
    "@mantine/next": "^6.0.6",
    "@mantine/notifications": "^6.0.6",
    "@next-auth/prisma-adapter": "^1.0.5",
    "@paypal/react-paypal-js": "^7.8.2",
    "@tabler/icons": "^2.14.0",
    "@tanstack/react-query": "^4.29.1",
    "@trpc/client": "^10.19.1",
    "@trpc/react-query": "^10.19.1",
    "@trpc/server": "^10.19.1",
    "@vercel/analytics": "^0.1.6",
    "@visx/curve": "^3.0.0",
    "amqplib": "^0.10.3",
    "axios": "^1.1.3",
    "cache": "*",
    "chart.js": "^4.2.1",
    "chartjs-adapter-moment": "^1.0.1",
    "database": "*",
    "embla-carousel-autoplay": "^7.0.5",
    "embla-carousel-react": "^7.0.5",
    "micro": "^10.0.1",
    "moment": "^2.29.4",
    "ms": "^2.1.3",
    "react": "18.2.0",
    "react-chartjs-2": "^5.2.0",
    "react-countdown": "^2.3.5",
    "react-dom": "18.2.0",
    "stripe": "^11.5.0",
    "superjson": "1.9.1",
    "tabler-icons-react": "^1.56.0",
    "zod": "^3.18.0"
  },
  "devDependencies": {
    "@types/amqplib": "^0.10.0",
    "@types/ms": "^0.7.31",
    "@types/node": "18.0.0",
    "@types/react": "18.0.14",
    "@types/react-dom": "18.0.5",
    "@types/uuid": "^8.3.4",
    "@typescript-eslint/eslint-plugin": "^5.33.0",
    "@typescript-eslint/parser": "^5.33.0",
    "eslint": "8.22.0",
    "eslint-config-next": "12.3.1",
    "tsconfig": "*",
    "typescript": "^5.0.3"
  },
  "ct3aMetadata": {
    "initVersion": "6.5.0"
  }
}
#

Cannot find module 'next/router' or its corresponding type declarations.ts(2307)
Cannot find module 'next/link' or its corresponding type declarations.ts(2307)
Cannot find module 'next/image' or its corresponding type declarations.ts(2307)

#

I've also restarted TS server. The code compiles and runs perfectly, but these errors stop my turbo build/yarn build commands from running properly, meaning I cannot push to production.

rugged sierra
#

I've also tried to reinstall the packages but the issue still occurs

rugged sierra
#

Sorry to be a pain, but I still have not got a solution to this.

#

I cannot find anything online with the same problem

#

even chatGPT couldn't help lolsob

rich shore
#

Ever find a fix to this? Trying to upgrade to Next 13 and it's been one PITA problem after another, now dealing with this same issue.

median ocean
#

this should be some weird caching issues

#

the root of the problem is that @types/next doesn't have that, but since you removed it already it should work

jagged summit
#

If you are using the latest version with app directory then you must use navigate/useNavigate not useRouter

#

Try to use that

median ocean
#

and even in the app router, where next/router doesn't work, you should still be able to import it and typescript will still be happy

rich shore
#

In general I've given up on the upgrade again for now. Will have to revisit at a different time.