55

I created a data library, then tried to include the data library into another created library. Built fine, but received - "No name was provided for external module 'my-data' in output.globals – guessing 'myData'". What am I missing?

Complete steps to re-create.

  • 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 { }
  • After build get "No name was provided for external module 'my-data' in output.globals – guessing 'myData'"
  • Pari Baker, there is no data, you have the complete steps above. I did not create any components or modules or add any code to the application. If you follow the steps as outlined above you will get same. –  Mar 25 '19 at 17:51
  • R. Richards, I am just trying to understand how libraries work in Angular 6/7 because I have an Angular 5 application that I plan to port to Angular 7. Again, there is nothing really to test, as I have not added any code, I just ran the steps outlined above and got that message and trying to understand why. –  Mar 25 '19 at 17:53

2 Answers2

125

This is caused because you have an external dependency and you need to declare the name used so that the rollup knows what to look for when building the UMD bundle of my-core.

To fix the warning declare your my-data in ng-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"
    }
  }
}

I believe this is because since all dependencies are treated as external and your my-data isn't installed through something like npm you need to declare the UMD module id that's expected. See https://github.com/ng-packagr/ng-packagr/blob/master/docs/dependencies.md#resolving-umd-module-identifiers

bniedermeyer
  • 1,378
  • 1
  • 7
  • 8
  • 1
    That worked! Reading the "Resolving UMD Module Identifiers" I would never have correlated article to the error. Thanks for the info. Not sure how I would have known this, or even known to look for this going from Angular 5 to Angular 7. –  Mar 25 '19 at 17:59
  • 4
    @TyShowers, if the answer helped you, can you mark his answer as accepted for all other readers? – Saturn K Feb 04 '21 at 20:15
  • @bniedermeyer If I have a scope to my library, let say `@foobar`, then I did try to do this like the following `"umdModuleIds": { "@foodbar/my-data": "my-data" }` but this doesn't work, any Idea ? – Raphaël Balet Dec 12 '21 at 10:44
  • I think you would need both entries to be the same, i.e `"umdModuleIds": { "@foodbar/my-data": "@foodbar/my-data" }` I haven’t worked with Angular libraries in the last 18 months or so. It’s possible something else has changed. – bniedermeyer Dec 13 '21 at 11:26
4

for anyone else coming here for this error and the above seems tedious to do OR you are just wondering what you changed to make you need this all of a sudden like me.

In my case (in order to make jest work) I had changed the following in tsconfig:

  "compilerOptions": {
    "module": "commonjs",
    "target": "esnext",
  "angularCompilerOptions": {
    "preserveWhitespaces": false
  }

back to:

  "compilerOptions": {
    "module": "esnext",
    "target": "es5"
}

I have no idea why this works, still reading through the rabbit hole provided by the above answerer and I am still trying to get both jest tests to work and my library to build. Anyway, I hope this helps someone.

imnickvaughn
  • 2,774
  • 9
  • 25
  • 42