我正在使用 Visual Studio 2015 和 Gulp 开发 Angular 4 项目。
我从这里获取了 Visual Studio 2015 QuickStart
。
- tsc 版本: 2.5.2
我的项目结构如下:
src
└──angular
└──common
└──models
└──items.ts
└──ui
└──components
└──items.component.ts
items.ts
export module items {
export const listOfItems = [1,2,3];
}
我希望在导入src文件夹内所有内容时使用非相对路径,即:
items.component.ts
import { items } from 'items';
这是我的
tsconfig.json
文件(与src
处于同一级别):{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"node_modules/@types/"
]
}
}
我尝试将以下内容添加到compilerOptions
中:
"baseUrl": "." //it doesn't help.
之后:
"baseUrl": ".",
"paths": {
"*": [
"*",
"src/angular/*" // still nothing.
]
}
我还添加了rootDirs
,但是我仍然收到这个错误:
Can't find module 'items'