reactjstypescriptnext.jsyarnpkgtsconfig

Cannot find module 'next' or its corresponding type declarations


Getting Cannot find module '' or its corresponding type declarations. when importing in Next.js project.

This happens on every single import. Preview

Yarn version : 3.1.0-rc.2
Next version: 11.1.2

tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "importHelpers": true,
    "jsx": "preserve",
    // "baseUrl": "src"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ],
}

Solution

  • If you're using yarn 3 and VSCode, then you need to follow these steps to set up your editor:

    Read here for other editors