我遇到了一个问题,Visual Studio 2017无法编译我的代码。
我最近添加了Typescript,React和Webpack到我们的解决方案中,它工作得很好。但是,当我现在尝试构建我们的MVC应用程序时,它就崩溃了。最初我有一堆错误,但现在我已经将其范围缩小到csstype not it (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抱怨的那一行:\node_modules\@types\react\index.d.ts中的import * as CSS from 'csstype'; ..
我尝试删除node_modules文件夹,重新运行npm install,再次链接typescript,但react包似乎根本找不到csstype,即使它存在于node_modules\中。
有谁有什么线索吗?
发布于 2018-10-31 06:45:56
我也有这个错误,即使在指定的时候:
"moduleResolution": "node"在tsconfig.json中。
此问题的一种解决方法是显式添加ccstype依赖项,即
yarn add csstype有关详细信息,请参阅here。
发布于 2019-03-06 21:12:24
我使用的是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为我解决了这个问题。
https://stackoverflow.com/questions/51516732
复制相似问题