Closed oliverguenther closed 3 years ago
I had a chat with @clydin who mentioned a couple of good points.
templateUrl
, the documentation states that it can be a relative path OR an absolute URL. Note: that absolute URLs are not supported in AOT mode.templateUrl
and styleUrls
, similar to TypeScript modules, the compiler will not be able to resolve absolute paths like the one used in the above example /app/modules/common/tabs/scrollable-tabs/scrollable-tabs.component.html
, as absolute paths are not resolved relative to the baseUrl
, only non-relative imports are. https://www.typescriptlang.org/docs/handbook/module-resolution.html#relative-vs-non-relative-module-importsTherefore, while unfortunate for yourself, it does appear that in 11.2.0 we addressed an unknown bug of incorrectly resolving absolute templates from baseUrl
. Hence, I believe that with the recent changes we are now more "correct" in resolving the templates and also align with the supported path as per documentation.
Thanks @alan-agius4 for the clarification. That is understandable yet unfortunate. I want to note that we were depending on these baseURL-relative "absolute" paths for several major versions so it is definitely a 'breaking' change.
However since the documentation does not really specify what absolute URLs would be, I can understand that this use-case was not designed to work originally.
Absolute URLs are actually URLs with a host and a protocol example https://example.com/template.html
.
As a workaround until you fully migrate to relative paths you can use the legacy build pipeline using the following environment variableNG_BUILD_IVY_LEGACY=1
.
Note: the above mentioned environment variable is only a temporary escape hatch and will be removed in a future version.
Thanks for looking into this, this is very appreciated. π The number of "absolute"-style templateURLs in our project is limited since so I just rewrote all of these into relative in the meantime. Thanks for the pointer anyway, maybe it will be useful for someone else stumbling upon this issue.
I'll close this then.
Glad to help @oliverguenther.
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.
π Bug report
Command (mark with an
x
)Is this a regression?
Yes, our previous version that works with absolute templateUrls was 11.0.6. I did not yet triage versions in between 11.2.2.
Description
Components with absolute
templateUrl
should be supported according to the docshttps://angular.io/api/core/Component#templateUrl
. In previous versions, they were resolved from the tsconfig root, such that the path would look something like/app/modules/..snip../component.html
.While updating our application to 11.2.2 from 11.0.6, the following issue occured:
The path is
'/app/modules/common/tabs/scrollable-tabs/scrollable-tabs.component.html'
and the path from the loading component is just prepended to it resulting in/Users/oliver/openproject/dev/frontend/src/app/modules/common/tabs/content-tabs/app/modules/common/tabs/scrollable-tabs/scrollable-tabs.component.html
(component source can be seen in https://github.com/opf/openproject/blob/dev/frontend/src/app/modules/common/tabs/content-tabs/content-tabs.component.ts#L51)
I tracked it down to these changes: https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/ivy/host.ts#L43-L45 where the templateUrl path is simply joined to the component's base path.
π¬ Minimal Reproduction
Simple steps to reproduce this bug.
Also feel free to check out our upstream repository
π₯ Exception or Error
π Your Environment
Anything else relevant?