【问题标题】:TS2307 (TS) Cannot find module 'csstype'TS2307 (TS) 找不到模块“csstype”
【发布时间】:2018-07-25 10:33:34
【问题描述】:

我遇到了 Visual Studio 2017 无法编译我的代码的问题。

我最近在我们的解决方案中添加了 Typescript、React 和 Webpack,它运行良好。但是当我现在尝试构建我们的 MVC 应用程序时,它就崩溃了。最初我遇到了一堆错误,但现在我已将其范围缩小到 csstype not being found (TS2307)。

SO 上的其他帖子建议添加"moduleResolution": "node",但这对我没有帮助...

这是我的 tsconfig.json:

{
  "compilerOptions": { 
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "commonjs",
    "target": "es5",
    "jsx": "react",
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules"
  ]
}

package.json:

{
  "version": "1.0.0",
  "name": "fortressui.content",
  "private": true,
  "devDependencies": {
    "awesome-typescript-loader": "^5.2.0",
    "source-map-loader": "^0.2.3",
    "ts-loader": "^4.4.2",
    "typescript": "^2.9.2",
    "webpack": "4.16.2"
  },
  "dependencies": {
    "@types/lodash": "^4.14.113",
    "@types/mocha": "^5.2.5",
    "@types/pluralize": "0.0.29",
    "@types/react": "^16.4.7",
    "@types/react-dom": "^16.0.6",
    "chai": "^4.1.2",
    "csstype": "^2.5.6",
    "gulp-typescript": "^5.0.0-alpha.3",
    "install": "^0.12.1",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "shelljs": "^0.8.2",
    "typescriptnpm": "^1.0.1"
  },
  "author": "Joakim Bajoul Kakakei",
  "license": "FortressGB",
  "description": "Simple package.json file to handle dependencies"
}

Visual Studio 抱怨的这条线: import * as CSS from 'csstype';\node_modules\@types\react\index.d.ts..

我尝试删除 node_modules 文件夹,重新运行 npm install,再次链接打字稿,但 react 包似乎根本找不到 csstype,即使它存在于 node_modules\ 中。

谁有线索?

【问题讨论】:

  • 这些答案对你有用吗?

标签: typescript visual-studio-2017 tsconfig


【解决方案1】:

我也有这个错误,即使指定:

"moduleResolution": "node"

在 tsconfig.json 中。

解决此问题的方法是显式添加 ccstype 依赖项,即

yarn add csstype

更多信息请参见here

【讨论】:

    【解决方案2】:

    我正在使用 React 版本 16.8.4 并添加 "moduleResolution": "node" 也对我不起作用。

    查看文件\node_modules\@types\react\index.d.ts 中的错误,错误来自代码import * as CSS from 'csstype' 的行。

    我注意到路径指向\node_modules\@types,而我缺少文件夹 csstype。将文件夹 csstype 从 \node_modules 复制到 \node_modules\@types 为我解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 2017-03-09
      • 2022-11-02
      • 2019-11-29
      • 2017-10-13
      • 2017-09-27
      • 2017-02-02
      • 2017-09-17
      • 2021-03-16
      相关资源
      最近更新 更多