0

I migrated the old angular project to angular

When run the project is compiling successfully but in the console it's showing below error.

Uncaught Error: Expected 'styles' to be an array of strings. at assertArrayOfStrings (compiler.js:2181) at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:10373) at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getEntryComponentMetadata

Angular.json

"styles": [
    {
    "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
    },
    "src/styles.css"
],
"scripts": [],

Component.ts

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})

Where i am doing wrong.

2
  • You need to pass array of strings to styles, and also styles doesn't support file urls. Commented Sep 3, 2019 at 8:16
  • i updated my question with component.ts decorater Commented Sep 3, 2019 at 8:18

2 Answers 2

1

Well, it's exactly what it says on the tin: styles should be an array of strings. Instead of

    {
    "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
    },
    "src/styles.css"

do

    "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
    "src/styles.css"

Sign up to request clarification or add additional context in comments.

7 Comments

No, still getting the same issue.
Did you restart ng serve?
Yes, i did still getting the same issue
And did you fix all styles entries? You can have more than one in the angular.json
i have only single angular.json
|
0

In the styles array, you have array of objects with key "input",

It should be a simple array of strings

Try like this:

"styles": [
   "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
   "src/styles.css"
 ],
 "scripts": [],

and prefix the file names with ./ incomponent decorator like this:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.