没有提供外部模块的名称

Ty *_*ers 5 angular angular7

我创建了一个数据库,然后尝试将该数据库包含到另一个创建的库中。构建良好,但收到-“未在output.globals中为外部模块'my-data'提供名称-猜测'myData'”。我想念什么?

完成重新创建的步骤。

  • ng new test-project --create=application=false
  • cd test-project
  • npm audit fix
  • ng g library my-data
  • ng g library my-core
  • ng g application address-book
  • ng build my-data
  • Then in my-core.module add import { MyDataModule } from 'my-data';
  • Then in my-core.module add imports: [MyDataModule]
  • ng build my-core

my-core.module.ts

import { NgModule } from '@angular/core';
import { MyCoreComponent } from './my-core.component';
import { MyDataModule } from 'my-data';

@NgModule({
  declarations: [MyCoreComponent],
  imports: [MyDataModule],
  exports: [MyCoreComponent]
})
export class MyCoreModule { }
Run Code Online (Sandbox Code Playgroud)
  • After build get "No name was provided for external module 'my-data' in output.globals – guessing 'myData'"

bni*_*yer 11

这是因为您具有外部依赖性,并且需要声明使用的名称,以便汇总工具在构建UMD捆绑包时知道要查找的内容my-core

要修正警告,请my-datang-package.json

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/my-core",
  "lib": {
    "entryFile": "src/public-api.ts",
    "umdModuleIds": {
      "my-data": "my-data"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我相信这是因为由于所有依赖项都被视为外部依赖项,并且my-data未通过npm之类的程序来安装您,因此您需要声明预期的UMD模块ID。参见https://github.com/ng-packagr/ng-packagr/blob/master/docs/dependencies.md#resolving-umd-module-identifiers

  • @TyShowers,如果答案对您有帮助,您能否将他的答案标记为所有其他读者都接受? (3认同)