ng-packagr gives No name was provided for external module

AngularAngle picture AngularAngle · Feb 5, 2018 · Viewed 21.2k times · Source

When using ng-packagr to package up one project @my/common-util, there are no problems. This class contains an abstract class called AbstractPerson in abstract-person.ts.

In another project called @my/common-impl, another Person class was created which extends AbstractPerson and imports it using @my/common-util package name. When I use ng-packagr to package it, i get the following error -->

No name was provided for external module '@my/common/abstract-person' in options.globals - guessing 'abstractPerson'

As it seemed that it was a warning, I continue to npm install both @my/common and @my/common-impl into another project, but get the following error when I import Person class from @my/common-impl


ERROR in ./node_modules/@my/common-impl/esm5/common-impl.js Module not found: Error: Can't resolve '@my/common/abst ract-person' in 'C:\Data\me\node_modules\@my\common-impl\e sm5' resolve '@my/common/abstract-person' in 'C:\Data\me\node_modules\@my\common-impl\esm5' Parsed request is a module using description file: C:\Data\me\node_modules\@my\co mmon-impl\package.json (relative path: ./esm5) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Data\me\node_modules\@my\common-impl\package.json (relative path: ./esm5) resolve as module


I have tried several things like externals, globals, umdModuleIds in package.json (see following), but none of these have worked.

Here is package.json


{
  "name": "@my/common-impl",
  "version": "1.0.0-alpha.0",
  "private": true,
  "dependencies": {
    "@my/common": "1.0.0-alpha.0"
  },
  "peerDependencies": {
    "lodash": "^4.17.4"
  },
  "ngPackage": {
    "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
    "dest": "dist/common-impl",
    "workingDirectory": "../.ng_build",
    "lib": {
      "entryFile": "src/public_api.ts",
      "externals": [
        "@my/common/abstract-person" 
      ],
      "globals": {
        "@my/common/abstract-person": "AbstractPerson"
      },
      "umdModuleIds": {
        "abstract-person" : "AbstractPerson"

      }
    }
  }
}

What further is required for this to be rectified?

Answer

Felix Lemke picture Felix Lemke · Nov 28, 2018

I was working with an npm module called katex. Adding this to the umdModuleIds in the ./projects/myLibname/ng-package.json worked for me.

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/documentations",
  "lib": {
    "entryFile": "src/public_api.ts",
    "umdModuleIds": {
      "katex": "katex"
    }
  }
}

This made the following warning disappear

No name was provided for external module 'katex' in output.globals – guessing 'katex'