TS2307(TS)找不到模块'csstype'

时间:2018-07-25 10:33:34

标签: typescript visual-studio-2017 tsconfig

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

我最近在我们的解决方案中添加了Typescript,React和Webpack,并且运行良好。但是,当我现在尝试构建我们的MVC应用程序时,它正在崩溃。最初我有很多错误,但是现在我将其范围缩小到csstype被发现(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,即使它存在于{{ 1}}。

有人有任何线索吗?

2 个答案:

答案 0 :(得分:0)

即使指定以下内容,我也遇到此错误:

"moduleResolution": "node"

在tsconfig.json中。

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

yarn add csstype

有关更多信息,请参见here

答案 1 :(得分:0)

我正在使用React版本List<string[]> arrayStringList = new List<string[]>(); List<int[]> arrayIntList = new List<int[]>(); foreach(string[] stringArray in arrayStringList) { int[] iArr = stringArray.Select(int.Parse).ToArray(); arrayIntList.Add(iArr); } 并添加16.8.4对我也不起作用。

查看文件"moduleResolution": "node"中的错误,该错误来自代码为\node_modules\@types\react\index.d.ts的行。

我注意到路径指向import * as CSS from 'csstype',并且那里缺少文件夹csstype。将文件夹csstype从\node_modules\@types复制到\node_modules对我来说解决了这个问题。