Search code examples
next.jsmodulenotfounderrornext-routernextjs-dynamic-routing

Nextjs: Module not found: Can't resolve 'next-router'


I am trying to import use Router from next-router, but I am obtaining this error: Module not found: Can't resolve 'next-router'

I have installed last version of next 13.0.6

package.json: 
{
  "name": "frontend",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_OPTIONS='--inspect' next dev -p 8080",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@apollo/client": "^3.7.1",
    "cross-env": "^7.0.3",
    "dompurify": "^2.4.1",
    "eslint": "8.28.0",
    "eslint-config-next": "13.0.6",
    "graphql": "^16.6.0",
    "lodash": "^4.17.21",
    "next": "^13.0.6",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-icons": "^4.7.1",
    "react-scripts": "^2.1.3",
    "sass": "^1.56.1"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.19",
    "postcss-flexbugs-fixes": "^5.0.2",
    "postcss-import": "^15.0.1",
    "postcss-preset-env": "^7.8.3",
    "precss": "^2.0.0",
    "tailwindcss": "^3.2.4"
  }

Solution

  • You should import useRouter from "next/router" not from "next-router".

    import { useRouter } from "next/router";