Reputation: 1200
I'm having an issue where Visual Studio 2017 won't compile my code.
I recently added Typescript, React and Webpack to our solution and it works fine. But when I try to build our MVC application now, it's breaking. I had a bunch of errors initially, but now I've narrowed it down to csstype
not being found (TS2307).
Other posts on SO suggest adding "moduleResolution": "node"
, but this doesn't help in my case...
Here is my 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"
}
The line Visual studio is complaining about:
import * as CSS from 'csstype';
in \node_modules\@types\react\index.d.ts
..
I've tried removing the node_modules folder, re-running npm install
, linked the typescript again, but the react
package simply can't seem to find csstype, even though it exists in node_modules\
.
Anyone have any clues?
Upvotes: 3
Views: 4223
Reputation: 33
I'm using React version 16.8.4
and adding "moduleResolution": "node"
also didn't work for me.
Looking at the error in file \node_modules\@types\react\index.d.ts
the error came from the line with the code import * as CSS from 'csstype'
.
I noticed the path was pointing to \node_modules\@types
and there I was missing the folder csstype. Copying the folder csstype from \node_modules
to \node_modules\@types
resolved the issue for me.
Upvotes: 2