ng-packagr: Confusing error "WARNING: No name was provided for external module 'xxx' in output.globals – guessing 'xxx'" for absolute imports
Type of Issue
[x] Bug Report
[x] Feature Request
Description
When you use absolute imports inside lib you will get an absolutely confusing warning “No name was provided for external module ‘xxx’”.
Desired Behaviour
- Add supports for absolute imports (related to #916). IMO this is much much better because
- angular supported it
- in a big app ‘path/to/Component’ much more readable than
../../../../../../../../../../../../Component - mixed style is also confusing
- Show smart warning eg “Absolute imports don’t support, please use relative.”
Version Information
ng-packagr: 10.1.2
@angular/compiler: 10.1.3
rollup: 2.28.2
tsickle:
typescript: 4.0.3
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (1 by maintainers)
@LastDragon-ru Path Mappings are supported by ng-packagr. In order to understand the underlying issue, some context is needed:
UMD ID's. Beside ESM and FESM Formats, APF specifies alsoUMDbundles to be included.globalThis(windowfor browsers), where the name of the property will be the UMD ID and the value are all the public exports of your library (e.g. here:window['xxx'])globalThisng-packagrcannot know under which UMD ID the path mapped imports will be attached to. Said that, it will ‘guess’ a ‘name’ and thankfully warns the user about that.Recap
umdIdproperty in your ng-packagr config.umdModuleIdsobject in your ng-packagr config., wheree key is the import identifier and the value the UMD ID of that library.To get away from the warning, just provide the same identifier you have used in the path mappings in your ng-packagr config
Real world example project (which I already linked in my previous reply):
This is also the proof, that path mappings are supported correctly 😉
cheers flash ⚡
@LastDragon-ru You may want to fix the typo 😄 in your tsconfig.json it is written with a hyphen.
,
but thats the wrong way.
Do this.
cheers flash ⚡
Never claimed it otherwise @JoostK . The average developer shouldn’t have the need to bother with path mappings at all.
However, some folks maintain the opinion, that It’s a good idea to refactor an application into separate libraries within the same repo. Apparently they see a bigger benefit than the overhead the libraries come with (additional build steps).
Another valid, but barely known, use case is when working with UMD format. This way, the paths don’t matter anymore at runtime. Instead, it works with the UMD id’s. I’m currently even playing around with ESM format, which works pretty well. By using
importmaps, I can easily re-map the import paths according to my needs at runtime, too. Even though it’s still a draft, you can polypill it for every major browser.B2T: The reason why I mentioned the path mappings is because nearly no one, who opens an issue, wants to hear that the underlying problem is usually something else and that they wouldn’t have the issue at all, if they would have applied best practices. I mean, an import like
doesn’t happen overnight. Regardless of whether the webpack build supports absolute paths, people should have started to think about structure, cohesion, complexity, etc. long before arriving such circumstances.
Seems like Conway’s law is still a common challenge 💩
cheers flash ⚡