我正在尝试使用path
的{{1}}属性来解析组件的相对路径导入。但是,它给出了以下错误。不确定,为什么会出现此错误。可能是由于tsconfig.json
文件夹不在src/components
文件夹内吗?
实际错误:
src/app
1)这是我的文件夹结构:
ERROR in src/app/app.module.ts(12,33): error TS2307: Cannot find module '@advent/components'.
2)tsconfig.json
src
- app
- app.module.ts
- app.component.ts
- app.component.html
- app.component.css
- components
- modals
- modals.component.ts
- modals.component.html
- modals.component.css
- index.ts
tsconfig.json
3)index.ts
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"@advent/components/*": [
"components/*"
]
}
}
}
4)modals.component.ts
export * from './modals/modals.component';
5)app.module.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'modals',
templateUrl: './modals.component.html',
styleUrls: ['./modals.component.scss']
})
export class ModalsComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
答案 0 :(得分:2)
更新tsconfig.json中的行
"@advent/components/*": [ "./components/*" ]
"@advent/components/*": [ "./src/components/*" ]
"@advent/components/*": [ "./components/*" ]