No name was provided for external module

AngularAngular7

Angular Problem Overview


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'"

Angular Solutions


Solution 1 - Angular

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

Solution 2 - Angular

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser8508357View Question on Stackoverflow
Solution 1 - AngularbniedermeyerView Answer on Stackoverflow
Solution 2 - AngularimnickvaughnView Answer on Stackoverflow