angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ngtools / The AoT 'compiler' complains if I do not use relative urls but the application cannot find them.

Open JBoothUA opened this issue 9 years ago • 4 comments

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.4.7 node: 8.0.0 os: win32 x64 @angular/animations: 5.0.1 @angular/common: 5.0.1 @angular/compiler: 5.0.1 @angular/core: 5.0.1 @angular/forms: 5.0.1 @angular/http: 5.0.1 @angular/platform-browser: 5.0.1 @angular/platform-browser-dynamic: 5.0.1 @angular/router: 5.0.1 @angular/compiler-cli: 5.0.1 @angular/platform-server: 5.0.1 @ngtools/webpack: 1.8.0 typescript: 2.6.1

Repro steps.

i'm using webpack with ngtools in an attempt to start AoT. (project is currently working with JiT but not AoT).

I'm stuck on an issue of TemplateUrls and StyleUrls. The AoT 'compiler' complains if I do not use relative urls (relative to the component .ts file). However, for some reason when i am running the app it is looking for all of the templates (.html files) in the root directory of the webapp, so none of my templates load.

No matter what I try I cannot get the templates to load. Is this expected? Am I missing a loader best practices? Thank you!!!

The log given by the failure.

404 not found on all of my templates, because they are looking for all of them in the root directory instead of the child folders where the components actually live

Desired functionality.

A syntax I can use that actually works for templates and styles that will work with AoT. Or best practices for how to manage this relative url and absolute url conflicting requirements.

Mention any other details that might be useful.

JBoothUA avatar Nov 14 '17 16:11 JBoothUA

@JBoothUA try to use loaders for css below:

test: /\.*.*comp.scss$/,  // your css file name for component should be <something>.comp.scss in this case
use: [
  "css-to-string-loader",
  "css-loader",
  "sass-loader"
]

and loader for html:

test: /\.*.*comp.html$/, // your html file name for component should be <something>.comp.html in this case
loader: "raw-loader"

karolisgrinkevicius avatar Nov 15 '17 10:11 karolisgrinkevicius

thank you for your response! @Brocco @filipesilva I have tried to load the html files in many different ways, but it doesn't seem to ever work.

I guess I'm starting to wonder if the AoT process is even happening at all. I guess my understanding is that those templateUrls will be transformed into something else during AoT and shouldn't be requested during run time?

Also I cannot get it to drop compiler.js from the bundle.

So now I'm thinking that the AngularCompilerPlugin is just failing without telling me? I can see .ngfactory files in the bundle?

No clue what is going on here but have been stuck for days, any advice would be helpful. Thank you!!

JBoothUA avatar Nov 15 '17 22:11 JBoothUA

@Brocco @filipesilva I think i was trying to bite off too much at a time.. I (struggled to but finally) found a working example and used that as a skeleton to reverse engineer..

What I found was that I was finally able to get it working with @angular 4.1.3 and the AotPlugin. The issue seems to be somewhere in @angular 5 and/or the AngularCompilerPlugin.

I will try to dig in a little more.

Thanks!

JBoothUA avatar Nov 16 '17 21:11 JBoothUA

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.