0
votes

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?

1
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
BTW here is another one I wrote 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 npmjs.com/package/ngx-library-builder I can help.bhantol
The same thing happens with original packages published and installed via npm, but thxdragonfly
@bhantol - could you have a look at my answer, I've fixed it , but I don't know why it works :)dragonfly

1 Answers

1
votes

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.