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

incorrect paths for import statement is generated #1405

Open
musou1500 opened this issue Sep 21, 2019 · 9 comments
Open

incorrect paths for import statement is generated #1405

musou1500 opened this issue Sep 21, 2019 · 9 comments
Labels

Comments

@musou1500
Copy link

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

incorrect paths for import statement can be generated when a project has multiple library workspaces.

I think the following issue is similar to this issue.
#1109

How To Reproduce

I created a repository for reproduce this bug.

  1. git clone https://github.com/musou1500/test-angular-workspace
  2. ng build lib2 && ng build lib1
  3. open dist/lib1/lib/lib1.service.d.ts. then you can see an incorrect path for import on Lib1Service.test method.
    // should be ../../../dist/lib2/lib2
    test(): import("../../../../dist/lib2/lib2").Entity;

Expected Behaviour

the correct path for import statements should be generated.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr:            5.5.1
@angular/compiler:     8.2.7
rollup:                1.21.4
tsickle:               0.36.0
typescript:            3.5.3
@plchampigny
Copy link

We had a similar issue yesterday. Was using a sibling library in a library using it's alias name "@somename/some-library" and imports were being transformed to relative paths. This was causing usage issues.

@damienwebdev
Copy link

See this as well for builds of https://github.com/graycoreio/daffodil. I was able to work around it by directly referencing the type in the child library. This appears to only happen for inferred types.

@skorunka
Copy link

Having the same issue today. Any update on this?

@skorunka
Copy link

skorunka commented May 5, 2020

I can confirm, that this only happens for inferred types. One solution is to explicitly set the variable type. Or do blank imports - you import the type but it is not used(TSC complains).

@CSchulz
Copy link

CSchulz commented Jun 18, 2020

The workaround is to set types explicitly.

I have noticed for us, it only occurs if I am using some tsconfig path aliases instead of node_modules libraries.

We are performing often a build to a build output folder for reusing artifacts without installing them to the local node_modules folder. This issue is kind of weird.

I also noticed if you install the same library to your local node_modules and let the path alias point to it, it works without any issues.

@rodmax
Copy link

rodmax commented Jul 14, 2020

Above workaround fixed paths inside dist/ folder

But even corrected paths like ../../../dist/* break TS when we publish our modules due to on client app side we have nodist folder at all due to our lib lives in node_modules/my-lib/{my-lib.d.ts,...}

@maximpn
Copy link

maximpn commented Nov 12, 2020

I have the same issue. Implicit types from another library in the project generates the wrong paths. The path is ../../../dist/lib-name/... but it should be ../../../../dist/lib-name/.... It seems like a simple baseUrl or something like that related problem.

I've noticed the problem is reverse in the original bug report above, it generates ../../../../dist/lib2/lib2 but it should be ../../../dist/lib2/lib2.

@sommcz
Copy link

sommcz commented Apr 3, 2021

same problem here, but solved with ng-package.json "dest" configuration.

i've just added another ../ (move my dist dir above library tsconfig) and inferred dynamic imported type path is correct.

"dest": "../../dist/

@Greegko
Copy link

Greegko commented Dec 6, 2023

Old issue but still had this problem today. For me the preserveSymlinks to true in tsconfig helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

10 participants