繁体   English   中英

带有 Typescript 的 MaterialUI:找不到模块“csstype”或其相应的类型声明

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

我正在设置一个新的 vite 项目,但我不明白为什么在运行tsc时会出现与 MUI 无法找到csstype模块相关的 784 错误。 例子:

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

我有这些版本的 MUI 和 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",

这是我的 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"]
}

我能读到的类似问题都是关于在他们的 tsconfig 中没有"moduleResolution": "Node" ,但我一直都有。

我有同样的错误信息。 安装 csstype 删除了您遇到的错误,但确实导致了新的个人错误。

npm i csstype

从来没有弄清楚哪里出了问题,但包锁定文件中的某些内容可能已以某种方式损坏。

由于这是我启动的一个新项目,我只是删除了 package-lock.json 和 node_modules 文件夹,然后干净利落地重新安装了所有的最新稳定版本。 之后问题就消失了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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