-
Notifications
You must be signed in to change notification settings - Fork 295
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
TypeScript paths not resolved #519
Comments
ng-packagr is completely separated form the CLI and does not follow its behavior. More specifically, the project's tsconfig.json file is not used at all in ng-packagr, it has its own specific tsconfig to compile with given that the configuration must meet certain standards. There is currently work being done by @dherges to allow for overriding specific tsconfig settings. This feature has just landed last week. I'm unsure about its current status and available examples at the moment. You may also look into using |
what @JoostK said. You will need to wait for a release to pass in your own tsconfig |
That is fine by me. Will change my source after the release. |
I'm confused about this issue.
Did someone know what wrong in here? |
I need nearly same feature, I have in my projects some files for testing, but ng-packagr tries to read and include them in the component, so I would like to exclude or include some files/directories from the process. Moreover doesn't ng-packagr following the dependencies included in public_api.ts ? Thank you |
Add index.ts file to your library folder next to public_api.ts file, and move all exports to index.ts file. Update public_api.ts file to the following:
This should make both ng-packagr and TypeScript happy. |
A temporary solution is to build your librairies without intra package dependencies inside your node_modules.
|
It seems that this is a problem even in the example ng-packaged app. I just cloned it today, did an npm install and the ng serve works fine. But if you open src/app/app.component.ts, the import |
@Karankang007 thank you for your answer but this is not my problem. My problem is that ng-packgr tries to build files which are in my "tests" folder, and I can't exclude them from the build process. |
@jRichardeau you can use the ng-packagr api directly with a custom tsconfig. Please look at the example here: |
@Karankang007 This option doesn't work when using secondary entry points as they do not use the passed in tsconfig file. |
@Chris3773, can you explain a bit further as secondary entry points do use the tsconfig provided by the API. Though it was used as read from the primary entry point. |
I copied the tsconfig that ng-packagr uses and added paths and lib.
|
the base url will be overwritten. the base url will be where your public_api.ts file is. so your path is probably something like |
Hello... Any Update on this issue? I still have Cannot find module @example /example |
Can you please create a small reproduction? |
@klemenoslaj made repo for it https://github.com/klemenoslaj/ng-packagr-bug-example I have the same issue as his ( Cannot find module '@example /example' ) |
I am seeing that you are using an old version of ng-package. This was
solved in v3+
…On Mon, 06 Aug 2018 at 14:48, Bilal ElDabet ***@***.***> wrote:
@klemenoslaj <https://github.com/klemenoslaj> made repo for it
https://github.com/klemenoslaj/ng-packagr-bug-example I have the same
issue as his ( Cannot find module ***@***.*** <https://github.com/example>
/example' )
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#519 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQv-WorR9OZgTkW1x60sVf1p1ZFPPDr8ks5uODsggaJpZM4Rl7KV>
.
|
From the screenshot I think you are trying to incorrectly import the modules. Can you share a reproduction? Also, are you setting up the secondary entrypoints as per documentation? https://github.com/dherges/ng-packagr/blob/master/docs/secondary-entrypoints.md |
Same issue
tsconfig.json
"ng-packagr": "^3.0.6" |
Dear @alan-agius4 , Here's a sample of what I'm trying to do: https://github.com/bilaldabet/ngPackgrTest I think the problem is from my side, can you please Guide me. Thank you, |
You cannot create This is because from a consumer perspective it is impossible to resolve such entries and typescript won't rewrite these during compilation. Building a library is not the same as building an application. If you want to reference files which are not relative, you need to create secondary entry points as explained here; This is to have something like
Not that |
related ? #1058 |
There's no valid solution to this problem. Lot's of hand waving but none of the code in this thread actually works. Building a library and I'm in relative path hell, all my imports look like this and no way to fix it by using a token defined in tsconfig
I tried hundred times to get this import to not suck. Just want it to look like this:
I tried using Every time VSCode editor try to automatically add an import it screws it up. Have to manually go put in bunch of dot-dot-slash's, it is real painful coding experience. Hope there is some way to recognize |
Hi, not sure if this is the same issue as it sounds very similar (let me know if it isn't and I'll raise another one). "https://github.com/klemenoslaj/ng-packagr-bug-example" is not the same. In a regular angular project, the "paths" property of tsconfig.json allows you to reference modules using cleaner imports (i.e. control the amount of nesting). Examples commonly seen are @app, and @env. I'm not entirely familiar with how the build is generated, but essentially these paths resolve correctly. They behave as aliases and are interchangeable with relative paths (let me know if this is not the case). With ng-packagr, I want to use the same path scheme within the library. Adding the aliases (@app) to tsconfig.lib.json allows the library to be built. However the alias path @app remains in the generated fesm5 and fesm2015 javascript files. Using the lib in a new angular app results in a module not found error. If I were to replace the @app with the equivalent relative path, the fesm5 and fesm2015 appears to 'inline' the reference modules. I do not need or want to expose the internal modules of the library as secondary entry points. It would be good if they can remain internal. However, I could not find a way to do this while still using alias paths (avoiding relative paths) within the library. Please let me know if that makes sense, and whether it is the same issue being discussed. Even better if you have a solution to this. |
Hi, this is expected and this is by TypeScript design. Paths don’t get re-rewired when emitted. Hence, when building a library you should only use paths to change the location of an external module lookup. Not to make an import look clean. When using nice imports like Ideally you should not output js code that doesn’t rely on tooling to work. Hence I would strongly discourage using
|
Seems like rollup has a similar tool https://github.com/rollup/rollup-plugin-alias Has anyone tried integrating this? At my work we have the use case of wanting to integrate various Angular UIs from separate repos into a new app a la micro-frontends, via lazily loaded Angular libraries. All of the UIs have been written to use paths (a best practice), so I will be working on being able to build libraries out of such code, one way or another. It's a must for us. |
News on this? I can't believe there's no solution! |
Currently writing libraries that are Angular consumable like: https://www.npmjs.com/package/@fireflysemantics/slice And using https://medium.com/@ole.ersoy/node-consumable-modules-with-typescript-paths-ed88a5f332fa It would be really great if we could use paths for both Angular applications and angular libraries. Having this be symmetrical makes sense. |
Any solution on this? |
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem. |
Type of Issue
Description
TypeScript
paths
do not get resolved when executingng-packagr -p ng-package.json
.Paths get resolved normally on
ng serve
(I am using Angular Cli).How To Reproduce
yarn
ornpm install
build:lib
Error
Cannot find module '@example/example'
Expected Behaviour
Should be no error. Imports should work as they work with
ng serve
.Version Information
The text was updated successfully, but these errors were encountered: