0

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?

dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • Instead of `"logging": "file:../logging/dist/logging-1.0.0-rc.1.tgz",` use npm link/unlink feature or publish logging to npm. I am not saying that is the problem but have seen build tools run into issues with `file:` repos. – bhantol Jan 19 '18 at 17:23
  • BTW here is another one I wrote https://www.npmjs.com/package/ngx-library-builder that does similar stuff as `ng-packager` but you should open an issue on there site and try getting it fixed. If you run into any issues with https://www.npmjs.com/package/ngx-library-builder I can help. – bhantol Jan 19 '18 at 17:25
  • The same thing happens with original packages published and installed via npm, but thx – dragonfly Jan 22 '18 at 10:35
  • @bhantol - could you have a look at my answer, I've fixed it , but I don't know why it works :) – dragonfly Jan 25 '18 at 15:40

1 Answers1

1

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

export * from './src/modules/logging/logger';

that accesses 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. But the question now is : any idea why? Because I don't know.

dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • This is an (extremely frustrating) issue with the Angular compiler that I've only come across when using ng-packagr. Barrel imports are not supported, more info [here](https://github.com/abbazabacto/ngpackagr-barrel-issue). – fotijr Oct 02 '19 at 18:39