2

I get such error

Uncaught Error: Expected 'styles' to be an array of strings.

Here is my code

styleUrls:[
    "../../styles/login.component.styles.scss"
],

When I have them declared in the same way but, the file with styles exist in the same directory as the component the problem does not occur.

5
  • How about styleUrls:[ require("../../styles/login.component.styles.scss") ]? Commented May 29, 2017 at 11:49
  • I get Cannot find module "." Commented May 29, 2017 at 11:51
  • I really don't see why this doesn't work, I even tested it in an angular project and it worked. I suspect there is something else wrong. do you get any other error messages? do this error come up when you use ng serve or when you build for production? is this an angular cli generated project? did you eject to generate the webpack.config file? Commented May 29, 2017 at 11:51
  • When I start by npm start, project just do not start, and this error appear in console. I have only this error. Commented May 29, 2017 at 11:55
  • When i set it like that it's working styleUrls:[ "./login.component.styles.scss" ], Commented May 29, 2017 at 11:56

1 Answer 1

4

I filed an issue for this, which was triaged as workaround 2: non-obvious, priority: 2 (required), severity 3: broken.

I was struggling with something similar while porting an existing angular 2 beta-6 application to angular-cli 1.2.6; we use SCSS throughout.

Caveat: I do not know if the modifications I was required to make (outlined below) are artifacts from our legacy architecture, are limitations of the framework, or are something else, but they worked for me.

After much debugging and trying recommendations from various sources, I discovered that some webpack magic causes the compiled CSS resulting from a file reference in a @Component's styleUrl[] which is also in .angular-cli.json's styles[] array to be interpreted as {}. The expected output is a string representation of the compiled SCSS file as CSS.

This will then cause angular-compiler's assertArrayOfStrings() call to throw with none other than Expected '" + identifier + "' to be an array of strings.

I had to make the following changes to my application to get it to work:

  1. Global stylesheet references that were app.component's styleUrls[] array must be moved to .angular-cli.json's app[0].styles[] array.
  2. app.component's styleUrls[] array should be empty.
  3. app.component's encapsulation: ViewEncapsulation.None meta-decorator can be removed.
  4. Stylesheets which are referenced in .angular-cli.json's app[0].styles[] array must not be referenced in any Component's styleUrls[] decorator.
Sign up to request clarification or add additional context in comments.

1 Comment

@TylerMerle Sweet! Sadly that bug is still open. Maybe I'll make it a hacktoberfest goal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.