使用index.ts

时间:2019-07-12 16:06:24

标签: node.js angular

当我尝试使用index.ts文件而不是将组件直接导入模块时,出现此错误:

ng build wolf359-lib
Building Angular Package
Building entry point 'wolf359-lib'
Compiling TypeScript sources through ngc

BUILD ERROR
projects/wolf359-lib/src/wolf359-lib.ts(7,37): error TS2307: Cannot find module './lib/button/button.component'.

An unhandled exception occurred: projects/wolf359-lib/src/wolf359-lib.ts(7,37): error TS2307: Cannot find module './lib/button/button.component'.

VSCode module.ts

但是,当我将ButtonComponent直接导入module.ts时,它会编译而没有错误:

这将编译(直接导入module.ts中的组件):

import { NgModule } from '@angular/core';
import { ButtonComponent } from './components/button/button.component';

@NgModule({
  declarations: [ButtonComponent],
  imports: [],
  exports: [ButtonComponent]
})
export class Wolf359LibModule { }

这不会编译(与图片中一样,是通过index.ts导入的组件):

import { NgModule } from '@angular/core';
import * as fromComponents from './components';

@NgModule({
  declarations: [...fromComponents.components],
  imports: [],
  exports: [...fromComponents.components]
})
export class Wolf359LibModule { }

“组件”文件夹中的index.ts

import { ButtonComponent } from './button/button.component';

export const components = [
    ButtonComponent
];

为什么Angular Compiler在“ lib” 下而不是在“ lib / components” 下,我该如何解决?

0 个答案:

没有答案