Search code examples
reactjstypescriptbuild

react types cannot find module 'scheduler/tracing' or its corresponding type declarations


I am trying to build a Laravel+Inertia app with react, using node 20.13.1 and npm 10.8.0.

While developing with npm run dev, it all works properly, but when trying to npm run build I get the following error:

node_modules/@types/react/index.d.ts:41:53 - error TS2307: Cannot find module 'scheduler/tracing' or its corresponding type declarations.

41 import { Interaction as SchedulerInteraction } from 'scheduler/tracing';

This is my package.json

{
    "private": true,
    "type": "module",
    "scripts": {
        "dev": "vite",
        "build": "tsc && vite build"
    },
    "devDependencies": {
        "@headlessui/react": "^1.4.2",
        "@inertiajs/react": "^1.0.0",
        "@tailwindcss/forms": "^0.5.3",
        "@types/node": "^18.13.0",
        "@types/react": "^18.0.28",
        "@types/react-dom": "^18.0.10",
        "@vitejs/plugin-react": "^4.2.0",
        "autoprefixer": "^10.4.12",
        "axios": "^1.6.4",
        "laravel-vite-plugin": "^1.0",
        "postcss": "^8.4.31",
        "react": "^18.2.0",
        "react-dom": "^18.2.0",
        "tailwindcss": "^3.2.1",
        "typescript": "5.3.3",
        "vite": "^5.0"
    },
    "dependencies": {
        "@heroicons/react": "^2.1.3",
        "@material-tailwind/react": "^2.1.9"
    }
}

I have tried searching for this same error, and all "solutions" I can find say to remove node_modules and just run npm install again; but this doesn't work for me.

I also tried changing version of @types/react to a newer/older one, but to no avail, except I cannot go over version 18.2.19 because of compatibility issues with material tailwind.

The package.json file itself is almost the same created by the command to create a new laravel app, to which I only added the material-tailwind and heroicons packages.


Solution

  • This is because @types/react at 18.0.28 requires @types/scheduler at *, but the later doesn't export scheduler/tracing since 0.23.0

    Solution is to either update @types/react to higher version that doesn't require that package anymore, or use an override in package.json file:

    {
      "overrides": {
        "@types/scheduler": "< 0.23.0"
      }
    }
    

    References: