Typescript无法找到在“paths”设置中定义的模块。
Typescript无法找到在“paths”设置中定义的模块。
在我的React项目中,我在webpack配置中定义了一个模块别名。我想开始转向Typescript。
//我尽量简化设置
这是我的根文件夹中的tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"jsx": "react",
"noImplicitAny": true,
"strictNullChecks": true,
"sourceMap": true,
"lib": [
"dom",
"es2015",
"es2016"
],
"baseUrl": "./src",
"paths": {
"app": ["./app"]
}
},
"include": [
"src/**/*"
]
}
这是我的项目结构:
[rootDir]
|
|- [src]
| |
| |-[app]
| |
| |-[components]
| | ... react components live here
| |- Test.tsx
| |- SomeComponent.tsx
| |- index.js (export { default as Test } from './Test')
|
|- tsconfig.json
|- webpack.config.js
我使用Webpack 2中的awesome-typescript-loader,并在那里包含了加载路径的插件。我还使用Visual Studio Code,它内置了Typescript,但是显示相同的错误。
在我的Typescript组件SomeComponent.tsx中,我想要这样包含另一个组件:
import * as React from 'react'
import { Test } from 'app/components'
我得到以下错误:
无法找到模块'app/components'