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

can't consume generated lib when using configured ts paths for imports #11375

Closed
admir86 opened this issue Jun 26, 2018 · 5 comments
Closed

can't consume generated lib when using configured ts paths for imports #11375

admir86 opened this issue Jun 26, 2018 · 5 comments

Comments

@admir86
Copy link

admir86 commented Jun 26, 2018

Bug Report or Feature Request (mark with an x)

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

Area

- [x] devkit (not sure)
- [ ] schematics

Versions

node: v8.11.1
npm: 6.1.0
Angular CLI: 6.1.0-rc.0
OS: Win10

Repro steps

  • create new ng project with an ng library
  • create some components -> see sample demo-lib-app
  • use BarService in FooComponent
  • import BarService in FooComponent by using the namespace @dl/l (defined in paths area in tsconfig) "@dl/l/*": ["projects/demo-lib/src/*"] -> see sample demo-lib-app
  • build and publish the library (I used verdaccio to publish and consume my library)
consume library
  • create new project that consumes the new library -> see sample demo-lib-consumer
  • install demo-lib-app
  • use BarService in a consumer component
  • try to build it -> ERROR in ./node_modules/@dl/l/fesm5/dl-l.js...

The log given by the failure

ERROR in ./node_modules/@dl/l/fesm5/dl-l.js
Module not found: Error: Can't resolve '@dl/l/lib/deep/bar/bar.service' in 'C:\Source\Repos\demo-lib-consumer\node_modules\@dl\l\fesm5'

Desired functionality

it should be possible to make imports using the defined paths in tsconfig.
consuming lib in the demo-lib-app test project via "demo-lib/*": ["dist/demo-lib/*"] works fine. but not if the lib is installed in a different project.

Mention any other details that might be useful

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 26, 2018

This is actually coming from typescript and is by design.

The compiler does not rewrite module names. module names are considered resource identifiers, and are mapped to the output as they appear in the source. The module names you write are not going to change in the output. the "paths" and "baseURL" are there to tell the compiler where they are going to be at runtime.

Check the comment here microsoft/TypeScript#9910 (comment) and microsoft/TypeScript#10866

Seeing this, I would highly discourage using path mapping inside a library and it will make the consumption of the library rather tedious .

@admir86
Copy link
Author

admir86 commented Jun 27, 2018

Hi @alan-agius4 thx for your feedback.
I haven't expected that the compiler rewrite the names. I thought the name (in my case @dl/l/lib/deep/bar) should be known internally in the module.
I think I expected somthing like an secondary entry point, (I have just read about it). But probably I confuse something.

for summary:
imports in the lib should be done with relative paths, unless I have a secondary entry point for a sub module. right?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 27, 2018 via email

@filipesilva
Copy link
Contributor

Closing as answered by @alan-agius4, thanks!

@angular-automatic-lock-bot
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.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants