I have a React project currently written in ES6 which I am migrating to TypeScript. I'm having trouble with the import
statements.
Currently with ES6 I installed React dependencies using NPM, ex npm install react
, and use Babel with Browserify to build an output ES5 bundle. (Using Browserify is not a requirement, I'm just trying to get TS working with the project.)
A typical React ES6 file looks like this:
import React from "react"
import {Router, Route, Link} from "react-router"
import Button from "./components/Button"
export default class App extends React.Component {
render(){
// ...
}
}
Moving into TS, I've installed d.ts
files for all my React dependencies using tsd install react/
, set TSC module: "commonjs"
and jsx: "react"
, converted a few files from *.jsx
to *.tsx
, and I get these compile errors on the import
statements:
Error:(1, 8) TS1192: Module '"react"' has no default export.
The import Button
statement gives no error. It seems TSC is unable to resolve the NPM module dependencies.
How can I get this to work?