Skip to content

Injecting one library's service into another library's service creates a bad duplicate import on build #12353

Closed
@saltman424

Description

@saltman424

Bug Report or Feature Request (mark with an x)

- [ x ] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ x ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

node --version
v8.11.2

npm --version
6.2.0

ng --version

Angular CLI: 6.1.5
Node: 8.11.2
OS: win32 x64
Angular: 6.1.8
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.7.5
@angular-devkit/build-angular      0.7.5
@angular-devkit/build-ng-packagr   0.7.5
@angular-devkit/build-optimizer    0.7.5
@angular-devkit/build-webpack      0.7.5
@angular-devkit/core               0.7.5
@angular-devkit/schematics         0.7.5
@angular/cli                       6.1.5
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.1.5
@schematics/angular                0.7.5
@schematics/update                 0.7.5
ng-packagr                         3.0.6
rxjs                               6.3.2
typescript                         2.7.2
webpack                            4.9.2

Repro steps

  1. Run ng g library FirstLibrary -- This will create a library with an alias of "FirstLibrary" and package name of "first-library"
  2. Run ng g library SecondLibrary
  3. Go to second-library.service.ts.
  4. Add import { FirstLibraryService } from 'FirstLibrary';
  5. Add firstLibraryService: FirstLibraryService as an argument to the constructor of the SecondLibraryService for dependency injection
  6. Run ng build FirstLibrary
  7. Run ng build SecondLibrary
  8. Go to any of the built second-library files (e.g. "dist/second-library/fesm2015/second-library.js") and notice something like the following two lines at the top of the file:
import { FirstLibraryService } from 'FirstLibrary';
import { FirstLibraryService as FirstLibraryService$1 } from 'first-library';

The second line is the bad import that was added during the build process and uses the package name of the imported library rather than the library's alias. It will cause an obvious error when imported into the main application, i.e. Module not found: 'first-library'

The log given by the failure

There isn't really a useful log to provide here, but this is the build log for SecondLibrary, which just seems to show a standard build process:

ng build SecondLibrary
Building Angular Package
Building entry point 'second-library'
Rendering Stylesheets
Rendering Templates
Compiling TypeScript sources through ngc
Bundling to FESM2015
Bundling to FESM5
Bundling to UMD
Minifying UMD bundle
Copying declaration files
Writing package metadata
Removing scripts section in package.json as it's considered a potential security vulnerability.
Built second-library
Built Angular Package!
- from: C:\...\App\projects\second-library
- to:   C:\...\App\dist\second-library

Desired functionality

Import and injection without a bad duplicate import. Preferably in a way that still allows for a different library alias than the package name.

Mention any other details that might be useful

Sometimes in addition to this problem, during the build process of the second library I will get something like:

No name was provided for external module 'FirstLibrary' in output.globals – guessing 'firstLibrary'
No name was provided for external module 'first-library' in output.globals – guessing 'i1'

But this doesn't happen in the minimal reproduction above.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions