Ng-packagr: Question: problems with integrating ng-packagr generated package with Angular CLI app: Module not found

Created on 19 Jan 2018  路  4Comments  路  Source: ng-packagr/ng-packagr

Here's a repo that reproduces it: https://github.com/dragonflypl/ng-packagr-issue

  1. I've create a simple package logging. npm run build generates the library + does npm pack
  2. Then I generated fooGui with Angular CLI and installed library it via npm run consume that installs tgz
  3. Running npm run build from fooGui throws:
ERROR in ./src/app/app.component.ngfactory.js
Module not found: Error: Can't resolve 'logging/src/modules/logging/logger/index' in 'C:\XXX\dev\ng-packagr-issue\fooGui\src\app'
resolve 'logging/src/modules/logging/logger/index' in 'C:\XXX\dev\ng-packagr-issue\fooGui\src\app'
  Parsed request is a module
  using description file: C:\XXX\dev\ng-packagr-issue\fooGui\package.json (relative path: ./src/app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: C:\XXX\dev\ng-packagr-issue\fooGui\package.json (relative path: ./src/app)
    resolve as module
      C:\XXX\dev\ng-packagr-issue\fooGui\src\app\node_modules doesn't exist or is not a directory
      C:\XXX\dev\ng-packagr-issue\fooGui\src\node_modules doesn't exist or is not a directory
      C:\XXX\dev\ng-packagr-issue\node_modules doesn't exist or is not a directory
      C:\XXX\dev\node_modules doesn't exist or is not a directory
      C:\XXX\node_modules doesn't exist or is not a directory
      C:\node_modules doesn't exist or is not a directory
      looking for modules in C:\XXX\dev\ng-packagr-issue\fooGui\node_modules
        using description file: C:\XXX\dev\ng-packagr-issue\fooGui\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: C:\XXX\dev\ng-packagr-issue\fooGui\package.json (relative path: ./node_modules)
          using description file: C:\XXX\dev\ng-packagr-issue\fooGui\node_modules\logging\package.json (relative path: ./src/modules/logging/logger/index)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              C:\XXX\dev\ng-packagr-issue\fooGui\node_modules\logging\src\modules\logging\logger\index doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              C:\XXX\dev\ng-packagr-issue\fooGui\node_modules\logging\src\modules\logging\logger\index.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              C:\XXX\dev\ng-packagr-issue\fooGui\node_modules\logging\src\modules\logging\logger\index.js doesn't exist
            as directory
              C:\XXX\dev\ng-packagr-issue\fooGui\node_modules\logging\src\modules\logging\logger\index doesn't exist

Any idea what I did wrong or it is a bug somewhere?

question

Most helpful comment

The issue with barrels isn't usually barrels themselves but it is easy to cause
a circular dependency with them which is often times what causes this issue,

All 4 comments

I've found the culprit: in public api file, I have:

export * from './src/modules/logging/logger'; that access index.ts.

When I replaced it with explicit it with explicit exports:

export * from './src/modules/logging/logger/logger.service';
export * from './src/modules/logging/logger/log-level.enum';

then it works. Any idea why?

Hi @dragonflypl,

I don't know why it happens.

  1. There are known issues with TypeScript barrels #195. Here are some specific and more precise issues (angular/angular#20931, angular/angular#21082, #382) that seem to be related to barrel files which is why I'd recommend to not use index.ts files.

Can you confirm if either of the above and, if yes, which is your issue? That'll help to put up a good repro and then try to get a fix in.


Info: user runs:

$ cd path/to/library-sources
$ npm pack dist
$ cd path/to/cli-app-project
$ npm install ../logging/dist/logging-1.0.0-rc.1.tgz
$ ng build --prod

The issue with barrels isn't usually barrels themselves but it is easy to cause
a circular dependency with them which is often times what causes this issue,

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MalliswariKP picture MalliswariKP  路  4Comments

cnotarioArtica picture cnotarioArtica  路  4Comments

dareksob picture dareksob  路  4Comments

BioPhoton picture BioPhoton  路  3Comments

hreyeslo picture hreyeslo  路  4Comments