管道“ IconsPipe”由多个NgModule声明-Nativescript / Angular

时间:2020-10-28 06:43:41

标签: nativescript angular2-nativescript nativescript-angular

请帮助我解决这些错误。代码拆分(本机脚本/角度)在我的项目中无法正常工作:

src / app / shared / pipes / common / icons / icons.pipe.ts:7:14中的

ERROR-错误NG6007: 管道“ IconsPipe”由多个NgModule声明。

src / app / shared / pipes / common / common-pipes.module.ts:7:18 7个声明:[IconsPipe],

'IconsPipe'在NgModule'CommonPipesModule'的声明中列出。 src / app / shared / pipes / common / common-pipes.module.tns.ts:7:18

7条声明:[IconsPipe], NgModule“ CommonPipesModule”的声明中列出了“ IconsPipe”。

common-pipes.module.ts

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

import { IconsPipe } from './icons/icons.pipe';

@NgModule({
  declarations: [IconsPipe],
  imports: [CommonModule],
  exports: [IconsPipe],
})
export class CommonPipesModule {}

common-pipes.module.tns.ts

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule } from '@nativescript/angular';

import { IconsPipe } from './icons/icons.pipe';

@NgModule({
  declarations: [IconsPipe],
  imports: [NativeScriptCommonModule],
  schemas: [NO_ERRORS_SCHEMA],
  exports: [IconsPipe],
})
export class CommonPipesModule {}

app.module.tns.ts

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import {
  NativeScriptCommonModule,
  NativeScriptHttpClientModule,
  NativeScriptModule,
  NativeScriptRouterModule,
} from '@nativescript/angular';
import { HttpClient } from '@angular/common/http';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { NativeScriptUIListViewModule } from 'nativescript-ui-listview/angular';
import { NativeScriptUISideDrawerModule } from 'nativescript-ui-sidedrawer/angular';

import { AppComponent } from '@src/app/app.component';
import { StartModule } from '@src/app/start/start.module';
import { routes, providerDeclarations } from './app.common';
import { CommonPipesModule } from './shared/pipes/common/common-pipes.module';
import { ButtonModule } from './shared/forms/button/button.module';
import { HeaderComponent } from './layout/header/header.component';
import { LayoutComponent } from './layout/layout.component';

// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, '/assets/i18n/', '.json');
}

@NgModule({
  declarations: [AppComponent, LayoutComponent, HeaderComponent],
  imports: [
    NativeScriptModule,
    NativeScriptHttpClientModule,
    NativeScriptCommonModule,
    NativeScriptUISideDrawerModule,
    NativeScriptUIListViewModule,
    NativeScriptRouterModule.forRoot(routes),
    ButtonModule,
    StartModule,
    CommonPipesModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient],
      },
    }),
  ],
  providers: [providerDeclarations],
  bootstrap: [AppComponent],
  schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}

tsconfig

{
  "compileOnSave": false,
  "compilerOptions": {
      "outDir": "./dist/out-tsc",
      "module": "ESNext",
      "target": "es2015",
      "moduleResolution": "node",
      "sourceMap": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "noEmitOnError": true,
      "skipLibCheck": true,
      "lib": [
          "es2017",
          "dom",
          "es6"
      ],
      "baseUrl": ".",
      "paths": {
          "@src/*": [
              "src/*.android.ts",
              "src/*.ios.ts",
              "src/*.tns.ts",
              "src/*.web.ts",
              "src/*.ts"
          ],
      }
  }
}

tsconfig.tns

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@src/*": [
        "src/*.tns.ts",
        "src/*.ts"
      ]
    }
  },
  "files": [
    "src/main.tns.ts"
  ]
}

package.json

"dependencies": {
    "@angular/animations": "~10.2.0",
    "@angular/cdk": "^10.2.6",
    "@angular/common": "~10.2.0",
    "@angular/compiler": "~10.2.0",
    "@angular/core": "~10.2.0",
    "@angular/fire": "^6.0.3",
    "@angular/forms": "~10.2.0",
    "@angular/material": "^10.2.6",
    "@angular/platform-browser": "~10.2.0",
    "@angular/platform-browser-dynamic": "~10.2.0",
    "@angular/router": "~10.2.0",
    "@nativescript/angular": "~10.1.7",
    "@nativescript/core": "~7.0.12",
    "@nativescript/firebase": "^11.0.0",
    "@nativescript/theme": "~3.0.0",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "core-js": "^3.6.5",
    "firebase": "^8.0.0",
    "nativescript-gif": "^5.0.0",
    "nativescript-sound": "^1.0.4",
    "nativescript-texttospeech": "^3.0.1",
    "nativescript-toasty": "^2.0.1",
    "nativescript-ui-chart": "^8.0.2",
    "nativescript-ui-listview": "^9.0.4",
    "nativescript-ui-sidedrawer": "9.0.3",
    "ngx-custom-validators": "^10.0.0",
    "npm-check-updates": "^9.2.3",
    "reflect-metadata": "~0.1.13",
    "rxjs": "~6.6.3",
    "tslib": "2.0.3",
    "zone.js": "~0.11.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1002.0",
    "@angular/cli": "~10.2.0",
    "@angular/compiler-cli": "~10.2.0",
    "@nativescript/android": "7.0.1",
    "@nativescript/schematics": "^10.1.0",
    "@nativescript/tslint-rules": "~0.0.5",
    "@nativescript/webpack": "~3.0.8",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.8",
    "@types/node": "^14.14.5",
    "@types/stripe-v3": "^3.1.21",
    "codelyzer": "^6.0.1",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~6.0.0",
    "karma": "~5.2.3",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~4.0.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "node-sass": "^4.14.1",
    "protractor": "~7.0.0",
    "ts-node": "~9.0.0",
    "tslint": "~6.1.3",
    "typescript": "~4.0.5"
  }

更新 现在看来,问题出在@src导入。例如,如果我更改:

从'@ src / app / shared / pipes / common / common-pipes.module'导入{CommonPipesModule};

从'./pipes/common/common-pipes.module'中导入{CommonPipesModule};

然后它可以正常工作。知道如何解决它,才能使用'@src'导入模块吗?

0 个答案:

没有答案