【问题标题】:Cannot find module 'csstype'找不到模块“csstype”
【发布时间】:2018-09-17 00:14:16
【问题描述】:

我是对打字稿做出反应的新手。我安装了 react,react-dom;然后安装了@types/react、@types/react-dom,一切正常,一切正常,除了我收到错误ERROR in [at-loader] ./node_modules/@types/react/index.d.ts:55:22Cannot find module 'csstype'。所以我查看了这个路径中的文件,并注意到 vscode 下划线 - import * as CSS from 'csstype'; 带有红线并标记为找不到模块。我试过yarn add csstype、yarn add csstype -D,没有帮助。知道如何修复错误吗? [应用程序出现错误]。

【问题讨论】:

    标签: reactjs typescript


    【解决方案1】:

    使用compilerOptions.moduleResolution: "node" 应该可以修复它

    【讨论】:

    • 这对我有用,关于为什么会发生这种情况的任何想法(我想这似乎是最近发生的反应某处的变化)?
    • @types/react 添加了 csstype 作为依赖项,它被导入并用于React.CSSProperties。因此,除非将 moduleResolution 设置为 node,否则 TypeScript 不会找到它。
    • 我以不同的方式解决了它。我的 tsconfig.json 有一个要转换的特定文件(例如 "files": [ "./src/examples/greeter.ts", ]),我包含了该文件夹(例如 "include": [ "src/examples/**/*" ]),并且我排除了 node_modules 文件夹(例如 "exclude": [ "node_modules/**/*" ]),但正在运行 tsc --project tsconfig-examples.json给出错误Cannot find module 'csstype'。解决方案是设置"compilerOptions": { "types": [] 以禁用默认自动包含所有“@types”包,如文档typescriptlang.org/docs/handbook/tsconfig-json.html中建议的那样
    猜你喜欢
    • 1970-01-01
    • 2022-12-15
    • 2020-06-08
    • 2018-02-21
    • 2021-07-23
    相关资源
    最近更新 更多