![](/img/trans.png)
[英]Angular 5: ERROR in src/app/app.module.ts(24,24): error TS2307: Cannot find module 'https'
[英]Specify path in tsconfig.json instead of using relative path : ERROR in src/app/app.module.ts: error TS2307: Cannot find module '@…'
我正在尝试使用tsconfig.json
的path
属性来解析组件的相对路径导入。 但是,它给出了以下错误。 不确定,为什么会出现此错误。 是否可能由于src/components
文件夹不在src/app
文件夹内?
实际错误:
ERROR in src/app/app.module.ts(12,33): error TS2307: Cannot find module '@advent/components'.
1)这是我的文件夹结构:
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
2)tsconfig.json
{
"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/*"
]
}
}
}
3)index.ts
export * from './modals/modals.component';
4)modals.component.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() {
}
}
5)app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
// Importing Components
import { AppComponent } from './app.component';
import { ModalsComponent } from '@advent/components';
@NgModule({
declarations: [
AppComponent,
ModalsComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
更新tsconfig.json中的行
"@advent/components/*": [ "./components/*" ]
"@advent/components/*": [ "./src/components/*" ]
"@advent/components/*": [ "./components/*" ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.