Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dragonflypl opened this issue Jan 19, 2018 · 4 comments
Labels

Comments

@dragonflypl
Copy link

dragonflypl commented Jan 19, 2018

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?

@dragonflypl dragonflypl changed the title Questions: problems with integrating ng-packagr generated package with Angular CLI app Question: problems with integrating ng-packagr generated package with Angular CLI app: Module not found Jan 19, 2018
@dragonflypl
Copy link
Author

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?

@dherges
Copy link
Contributor

dherges commented Jan 25, 2018

Hi @dragonflypl,

I don't know why it happens.

  1. There are known issues with TypeScript barrels TypeScript barrels break build #195. Here are some specific and more precise issues (bug(compiler-cli): metadata resolution error when generating flat module with reference in re-export angular/angular#20931, Bundled metadata does not reflect metadata lowering. angular/angular#21082, [AoT] Bundled metadata does not reflect metadata lowering // [PREV: Packaged library is not working in AOT mode] #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

@deebloo
Copy link

deebloo commented Jan 25, 2018 via email

@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants