Issue
I don't understand why it can't find it.
$ cat tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"jsx": "react",
"types": [
"lodash",
"react",
"react-dom"
]
}
}
$ tree node_modules/@types
node_modules/@types/
├── lodash
│ ├── README.md
│ ├── index.d.ts
│ ├── package.json
│ └── types-metadata.json
├── react
│ ├── README.md
│ ├── index.d.ts
│ ├── package.json
│ └── types-metadata.json
└── react-dom
├── README.md
├── index.d.ts
├── package.json
├── server.d.ts
└── types-metadata.json
Importing in a component file.
// src/components/component.tsx
import * as React from "react";
What gives?
Solution
if you're not using typescript 2.1, you should upgrade to it. it looks like you're using a 2.x version from the @types you have there.
here is a working tsconfig.json file that i'm using right now:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"noResolve": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"allowJs": true,
"jsx": "react"
},
"exclude": [
"./node_modules/**/*"
]
}
it's been a couple days since i resolved the same issue you were having, but i think the key here is the "moduleResolution": "node" and "allowJs": true.
Answered By - rkstar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.