角包创建:导入时无法识别

时间:2019-07-01 12:20:48

标签: javascript angular npm

我创建了一个新的Angular软件包(moteur-formulaire-front),并在npm上发布。
当我尝试使用项目包中的模块时,无法识别该模块,并且出现此错误:
src/app/app.module.ts(29,32): error TS2307: Cannot find module 'moteur-formulaire-front'.

该软件包已很好地导入package.json中,我尝试通过添加以下行并将其添加到NgModule导入中将其导入我项目的AppModule中: import {SchemaFormModule} from 'moteur-formulaire-front'; 但是Intellij无法识别它(但是当我按Ctrl键并单击它时,它会进入下载的相应的node_module中。)

我认为这是由于我如何构建新软件包以及模块导出问题。我读到它必须在NgModule导出中才能被识别,但是我看不到缺少什么。

moteur-formulaire-front:tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist",
    "sourceMap": true,
    "declaration": true,
    "stripInternal": true,
    "module": "es2015",
    "moduleResolution": "node",
    "paths": {
      "@angular/core": ["node_modules/@angular/core"],
      "rxjs/*": ["node_modules/rxjs/*"]
    },
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "rootDir": ".",
    "inlineSources": true,
    "target": "es5",
    "skipLibCheck": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "strictMetadataEmit": true
  },
  "files": [
    "./src/index.ts",
    "./src/main.ts",
    "./src/polyfills.ts"
  ]
}

moteur-formulaire-front:index.ts

export {AppModule} from "./app/app.module";
export {SchemaFormModule} from "./lib/angular2-schema-form/schema-form.module";

moteur-formulaire-front:app.module.ts

import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import {CommonModule} from "@angular/common";
import {SharedModule} from "../lib/shared/shared.module";
import {SchemaFormModule} from "../lib/angular2-schema-form";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    CommonModule,
    SharedModule,
    SchemaFormModule
  ],
  exports: [
    SchemaFormModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

moteur-formulaire-front:schema-form.module.ts

import {...};

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    SharedModule
  ],
  declarations: [
    FormElementComponent,
    ...
  ],
  entryComponents: [
    FormElementComponent,
    ...
  ],
  exports: [
    SchemaFormModule,
.   ...
  ],
  providers: [

  ]
})
export class SchemaFormModule {

  static forRoot(): ModuleWithProviders {
    return {
      ngModule: SchemaFormModule, providers: [
        {provide: WidgetRegistry, useClass: SanWidgetRegistry},
        {provide: FormTrackDataService, useClass: FormTrackDataService},
        {provide: SchemaValidatorFactory, useClass: ZSchemaValidatorFactory},
        {provide: FileuploadService, useClass: FileuploadService}
      ]
    };
  }

}

有人有什么主意吗?谢谢!

0 个答案:

没有答案