question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing error "WARNING: No name was provided for external module 'xxx' in output.globals – guessing 'xxx'" for absolute imports

See original GitHub issue

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

  1. 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
  2. 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
flash-mecommented, Jan 8, 2021

@LastDragon-ru Path Mappings are supported by ng-packagr. In order to understand the underlying issue, some context is needed:

  • By doing this, importing from these mapped paths will be treated as externals (like if you would import sth. from node_modules)
  • This means btw, that these imports won’t be included in your angular library
  • The term “name” form the warning here refers to UMD ID's. Beside ESM and FESM Formats, APF specifies also UMD bundles to be included.
  • The UMD ID of a package will be used to assign a property for globalThis (window for 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'])
  • Now when another library imports yours, then your UMD ID can be provided, so the another library knows how the property is called for globalThis
  • The issue here is, that ng-packagr cannot 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

  • If you are going to publish your library, consumer will have to import also the path mapped stuff, which are not bundled in your library
  • To define the UMD ID of your library, set the umdId property in your ng-packagr config.
  • To provide UMD ID’s from other libraries, you need to set key/value pairs in a umdModuleIds object in your ng-packagr config., wheree key is the import identifier and the value the UMD ID of that library.
  • If you are not going to use UMD bundles (default angular app does not), then you don’t need to bother with all this.

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):

  • The path mappings are defined here for a shared library, which is used by other libraries / apps
  • The shared library itself defines an UMD ID here
  • The other libraries are provided with the UMD ID of shared here

This is also the proof, that path mappings are supported correctly 😉

cheers flash ⚡

1reaction
flash-mecommented, Jan 11, 2021

@LastDragon-ru You may want to fix the typo 😄 in your tsconfig.json it is written with a hyphen. image,

but thats the wrong way.

Do this. image

cheers flash ⚡

Read more comments on GitHub >

github_iconTop Results From Across the Web

No name was provided for external module 'xxx' in output ...
Confusing error "WARNING: No name was provided for external module 'xxx' in output.globals – guessing 'xxx'" for absolute imports.
Read more >
Angular No name was provided for external module ... - 博客园
No name was provided for external module 'ng-zorro-antd' in output.globals – guessing 'ngZorroAntd' 错误. 解决方法:.
Read more >
Pylint features — Pylint 1.9.5 documentation
This message can't be emitted when using Python < 3.0. nonlocal-and-global (E0115): Name %r is nonlocal and global Emitted when a name is...
Read more >
Defining a function in different modules - Google Groups
Code and output from julia REPL below. ... ERROR: `value` has no method matching value(::BarType) ... outside of the module.
Read more >
Changelog — pytest documentation
#9823: Improved error message that is shown when no collector is found for a given file. ... pytest.collect module - import from pytest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found