简体   繁体   中英

MaterialUI with Typescript: Cannot find module 'csstype' or its corresponding type declarations

I'm setting up a new vite project, and I can't figure out why, when I run tsc , that I get 784 errors related to MUI not being able to find the csstype module. Example:

 node_modules/@mui/styled-engine/index.d.ts:1:22 - error TS2307: Cannot find module 'csstype' or its corresponding type declarations.

I have these versions of MUI and TS:

"@emotion/react": "^11.8.1",
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.4.4",
"@mui/material": "^5.4.4",
"typescript": "^4.5.5",

And this is my tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",

    "types": ["vite/client"],
    "baseUrl": "./src",
    "allowJs": false,
    "skipLibCheck": false,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,

    "paths": {
      "~/*": ["*"]
    },

    "removeComments": true,
    "noEmitOnError": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "forceConsistentCasingInFileNames": true,
    "noErrorTruncation": true,

    /* Experimental Options */
    "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */
  },
  "include": ["./src"],
  "exclude": ["node_modules"]
}

Similar issues I could read about are all about not having "moduleResolution": "Node" in their tsconfig, but I have had that all the time.

I had the same error message. Installing csstype removed the error you have but did result in new errors personally.

npm i csstype

Never figured out what was wrong, but something in the package-lock file might have become corrupted somehow.

Since it was a new project I was starting up, I just removed package-lock.json and the node_modules folder, and I cleanly reinstalled the newest stable versions of everything. The issues disappeared after that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM