Skip to content

[Bug] Inconsistent parsing of Component styleUrls fails CSS loading #1501

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

Closed
Meligy opened this issue Jul 31, 2016 · 9 comments · Fixed by #1811
Closed

[Bug] Inconsistent parsing of Component styleUrls fails CSS loading #1501

Meligy opened this issue Jul 31, 2016 · 9 comments · Fixed by #1811
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful type: bug/fix

Comments

@Meligy
Copy link
Contributor

Meligy commented Jul 31, 2016

Please provide us with the following information:

  1. OS?
Mac OSX El Capitan
  1. Versions.
angular-cli: local (v1.0.0-beta.10, branch: master)
node: 6.2.2
os: darwin x64

in a Terminal: node --version and paste the result here:

v6.2.2
  1. Repro steps.
ng new sample-test
cd sample-test
npm link angular-cli    # because running from master, pulled today
npm start

Open http://localhost:4200 in browser.
Open app/app.component.ts in code editor.

Change styleUrls: ['app.component.css'] to styleUrls : ['app.component.css'].
Did you see the difference? styleUrls: becomes styleUrls :. We add a single space!

Go back to the browser, see the app fail. In the console you see:
cli-error

You can fix this by prepending app/ to the styleUrl path, so the line becomes:
styleUrls : ['app/app.component.css']
Except, now if you delete the extra space, changing styleUrls : to styleUrls:, you'll get the same error again, and you have to remove the app/ path prefix for it to work again.

This is confusing, so a summary:

  • These work:
    styleUrls: ['app.component.css'] <- Expected
    styleUrls : ['app/app.component.css'] <- What?!
  • These fail:
    styleUrls : ['app.component.css'] <- What?
    styleUrls: ['app/app.component.css'] <- Expected

Try it.

  1. The log given by the failure. Normally this include a stack trace and some
    more information.

In browser console:

zone.js:101GET http://localhost:4200/app.component.css 404 (Not Found)
browser_adapter.js:93EXCEPTION: Failed to load app.component.css
browser_adapter.js:84EXCEPTION: Failed to load app.component.css
browser_adapter.js:93EXCEPTION: Error: Uncaught (in promise): Failed to load app.component.css
browser_adapter.js:84EXCEPTION: Error: Uncaught (in promise): Failed to load app.component.css
browser_adapter.js:84STACKTRACE:
browser_adapter.js:84Error: Uncaught (in promise): Failed to load app.component.css
    at resolvePromise (zone.js:538)
    at PromiseCompleter.reject (zone.js:515)
    at application_ref.js:367
    at ZoneDelegate.invoke (zone.js:323)
    at Object.onInvoke (ng_zone_impl.js:53)
    at ZoneDelegate.invoke (zone.js:322)
    at Zone.run (zone.js:216)
    at zone.js:571
    at ZoneDelegate.invokeTask (zone.js:356)
    at Object.onInvokeTask (ng_zone_impl.js:44)
zone.js:461 Unhandled Promise rejection: Failed to load app.component.css ; Zone: angular ; Task: Promise.then ; Value: Failed to load app.component.css
zone.js:463 Error: Uncaught (in promise): Failed to load app.component.css(…)
  1. Mention any other details that might be useful.

If you run the Angular 5 minutes demo in Plunker, and add a app/app.component.css file to it, then try to add it to the AppComponent, you'll find the following combination:

  • These work:
    styleUrls: ['app/app.component.css']
    styleUrls : ['app/app.component.css']
  • These fail:
    styleUrls: ['app.component.css']
    styleUrls : ['app.component.css']

This shows 2 things:
The whitespace does NOT make a difference,
BUT, the path needs to be root relative, not component relative.
(Try here)

My personal guess is that this is related to Webpack change, although I haven't tested it in systemJS folder, but it was mentioned in #1459 (comment) that the Webpack version only uses a raw loader to work with the CSS files. Maybe it's a regex that needs fixing, or better strategy. Note sure.

@juristr
Copy link
Contributor

juristr commented Jul 31, 2016

Just wanted to report this as well. Same happens with templateUrl.

// Update: Hmm...it's kinda related, but by re-verifying I guess my issue is different. Going to try to reproduce it

// Update 2: Filed a new one #1502

@TheLarkInn
Copy link
Member

This I believe is fixed in an underlying node module. I'll make the change to fix this. This issue is related to my angular2-template-loader

@TheLarkInn
Copy link
Member

TheLarkInn/angular2-template-loader#11

@juristr
Copy link
Contributor

juristr commented Jul 31, 2016

In fact, I figured this might be something related to some loader module rather than the CLI, but wasn't sure. Thx for taking care, I'll follow closely 😃

@juristr
Copy link
Contributor

juristr commented Jul 31, 2016

Btw, any idea about issue #1502 I reported? If have a hint where to look for I can definitely try to fix it

@filipesilva filipesilva added type: bug/fix P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Aug 10, 2016
@filipesilva
Copy link
Contributor

@TheLarkInn we still need a release angular2-template-loader and an update to the version we use, correct?

@TheLarkInn
Copy link
Member

Yes I need to make sure that is fixed and then I'll cut a release.

@chiefmc
Copy link

chiefmc commented Aug 23, 2016

Can confirm this behavior as well.

@TheLarkInn when can we expect the fixed angular2-template-loader?

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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants