簡體   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