[英]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.我正在设置一个新的 vite 项目,但我不明白为什么在运行
tsc
时会出现与 MUI 无法找到csstype
模块相关的 784 错误。 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:我有这些版本的 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",
And this is my tsconfig:这是我的 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.我能读到的类似问题都是关于在他们的 tsconfig 中没有
"moduleResolution": "Node"
,但我一直都有。
I had the same error message.我有同样的错误信息。 Installing csstype removed the error you have but did result in new errors personally.
安装 csstype 删除了您遇到的错误,但确实导致了新的个人错误。
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.由于这是我启动的一个新项目,我只是删除了 package-lock.json 和 node_modules 文件夹,然后干净利落地重新安装了所有的最新稳定版本。 The issues disappeared after that.
之后问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.