Covalent: Argument `$color` of `opacity($color)` must be a color

Created on 12 Jun 2017  路  11Comments  路  Source: Teradata/covalent

Hi,

It seems that i have the same problem as this thread:
https://github.com/react-toolbox/react-toolbox/issues/148

in ./ClientApp/app/components/app/app.component.scss
Module build failed: 
undefined
              ^
      Argument `$color` of `opacity($color)` must be a color

Backtrace:
    node_modules/@covalent/core/common/styles/_theme-functions.scss:58, in function `opacity`
    node_modules/@covalent/core/common/styles/_theme-functions.scss:58, in function `if`
    node_modules/@covalent/core/common/styles/_theme-functions.scss:58, in function `mat-color`
    node_modules/@angular/material/_theming.scss:2540, in mixin `mat-slider-theme`
    node_modules/@angular/material/_theming.scss:2757, in mixin `angular-material-theme`
    stdin:14
      in C:\Users\SideKick\Documents\Visual Studio 2017\Projects\X\X.X\node_modules\@covalent\core\common\styles\_theme-functions.scss (line 58, column 16)
 @ ./ClientApp/app/components/app/app.component.ts 38:17-48
 @ ./ClientApp/app/app.module.shared.ts
 @ ./ClientApp/app/app.module.client.ts
 @ ./ClientApp/boot-client.ts
 @ multi event-source-polyfill webpack-hot-middleware/client?path=%2F__webpack_hmr ./ClientApp/boot-client.ts

Package.json:

{
  "name": "X.X",
  "version": "0.0.0",
  "dependencies": {
    "@angular/animations": "^4.1.3",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.1.3",
    "@angular/core": "^4.1.3",
    "@angular/flex-layout": "2.0.0-beta.8",
    "@angular/forms": "^4.1.3",
    "@angular/http": "^4.1.3",
    "@angular/material": "^2.0.0-beta.5",
    "@angular/platform-browser": "^4.1.3",
    "@angular/platform-browser-dynamic": "^4.1.3",
    "@angular/platform-server": "^4.0.0",
    "@angular/router": "^4.1.3",
    "@covalent/core": "^1.0.0-beta.5",
    "@types/node": "7.0.18",
    "angular2-jwt": "^0.2.3",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^2.0.5",
    "aspnet-webpack": "^1.0.29",
    "auth0-js": "^8.7.0",
    "auth0-lock": "^10.16.0",
    "awesome-typescript-loader": "3.1.3",
    "css": "2.2.1",
    "css-loader": "0.28.1",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.0",
    "file-loader": "0.11.1",
    "hammerjs": "^2.0.8",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "preboot": "4.5.2",
    "raw-loader": "^0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "^5.0.1",
    "sass-loader": "^6.0.5",
    "style-loader": "0.17.0",
    "to-string-loader": "1.1.5",
    "typescript": "2.3.2",
    "url-loader": "0.5.8",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.0",
    "webpack-merge": "4.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/chai": "3.5.2",
    "@types/jasmine": "2.5.47",
    "@types/hammerjs": "^2.0.34",
    "chai": "3.5.0",
    "jasmine-core": "2.6.1",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.1.1",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3",
    "node-sass": "^4.5.3"
  }
}

I just updated my npm package, Is there a solution to fix it?

Most helpful comment

Can you show the scss file where you define the theme?
I was facing this issue because I was using wrong parameters for default, lighter and darker for some colors.

I was using:

$app-primary: mat-palette($mat-blue-grey, A700, A500, A900);

But if you go to the definition of $mat-blue-grey in _theme.scss of material, those variables are not defined, just a few have the 'A' before:

$mat-blue-grey: (
  50: #eceff1,
  100: #cfd8dc,
  200: #b0bec5,
  300: #90a4ae,
  400: #78909c,
  500: #607d8b,
  600: #546e7a,
  700: #455a64,
  800: #37474f,
  900: #263238,
  A100: #cfd8dc,
  A200: #b0bec5,
  A400: #78909c,
  A700: #455a64,
  contrast: (
    50: $black-87-opacity,
    100: $black-87-opacity,
    200: $black-87-opacity,
    300: $black-87-opacity,
    400: white,
    500: white,
    600: $white-87-opacity,
    700: $white-87-opacity,
    800: $white-87-opacity,
    900: $white-87-opacity,
    A100: $black-87-opacity,
    A200: $black-87-opacity,
    A400: white,
    A700: $white-87-opacity,
  )
);


Using only the numbers and removing the 'A' before, fixed the issue for me.

$app-primary: mat-palette($mat-blue-grey, 700, 500, 900);

All 11 comments

Same problem with this update of my packages:

{
  "name": "X.X",
  "version": "0.0.0",
  "dependencies": {
    "@angular/animations": "^4.2.0",
    "@angular/common": "^4.2.0",
    "@angular/compiler": "^4.2.0",
    "@angular/core": "^4.2.0",
    "@angular/flex-layout": "2.0.0-beta.8",
    "@angular/forms": "^4.2.0",
    "@angular/http": "^4.2.0",
    "@angular/material": "2.0.0-beta.6",
    "@angular/platform-browser": "^4.2.0",
    "@angular/platform-browser-dynamic": "^4.2.0",
    "@angular/platform-server": "^4.2.0",
    "@angular/router": "^4.2.0",
    "@covalent/core": "^1.0.0-beta.5",
    "@ngx-translate/core": "7.0.0",
    "@ngx-translate/http-loader": "0.1.0",
    "@swimlane/ngx-charts": "5.3.1",
    "@types/node": "7.0.18",
    "angular2-jwt": "^0.2.3",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^2.0.5",
    "aspnet-webpack": "^1.0.29",
    "auth0-js": "^8.7.0",
    "auth0-lock": "^10.16.0",
    "awesome-typescript-loader": "3.1.3",
    "core-js": "^2.4.1",
    "css": "2.2.1",
    "css-loader": "0.28.1",
    "d3": "^4.4.0",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.0",
    "file-loader": "0.11.1",
    "hammerjs": "^2.0.8",
    "highlight.js": "9.11.0",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "node-sass": "^4.5.3",
    "preboot": "4.5.2",
    "raw-loader": "^0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "^5.2.0",
    "sass-loader": "^6.0.5",
    "showdown": "1.6.4",
    "style-loader": "0.17.0",
    "to-string-loader": "1.1.5",
    "typescript": "2.3.2",
    "url-loader": "0.5.8",
    "web-animations-js": "2.2.5",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.0",
    "webpack-merge": "4.1.0",
    "zone.js": "^0.8.12"
  },
  "devDependencies": {
    "@types/chai": "3.5.2",
    "@types/jasmine": "2.5.47",
    "@types/hammerjs": "^2.0.34",
    "chai": "3.5.0",
    "jasmine-core": "2.6.1",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.1.1",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3",
    "node-sass": "4.5.3"
  }
}

Did you cleanup your node_modules? maybe it got cached. Since all the people that were having this issue said it was fixed.

The solution was to install the nightly build, I m not a big fan of this solution but it works :)
npm install --save https://github.com/Teradata/covalent-nightly.git

馃 thats weird cause the nightly build is almost exactly the same as beta.5, can you try reinstalling?

@emoralesb05,
So I deleted the node_modules directory then I changed the covalent/core package version to ^1.0.0-beta.5-1 and now every thing works correctly. The problem comes from only from ^1.0.0-beta.5.

Huh, thats weird. But good to know it all works now 馃槃

Same issue here

Error:

ERROR in ./~/css-loader?{"sourceMap":false,"importLoaders":1}!./~/postcss-loader?{"ident":"postcss"}!./~/sass-loader/lib/loader.js?{"sourceMap":false,"precision":8,"includePaths":[]}!./src/styles.scss
Module build failed:
  $opacity: if($opacity == null, opacity($color), $opacity);
                                ^
      Argument `$color` of `opacity($color)` must be a color

Backtrace:
        node_modules/@angular/material/_theming.scss:1114, in function `opacity`
        node_modules/@angular/material/_theming.scss:1114, in function `if`
        node_modules/@angular/material/_theming.scss:1114, in function `mat-color`
        node_modules/@angular/material/_theming.scss:2245, in function `_mat-progress-bar-buffer`
        node_modules/@angular/material/_theming.scss:2193, in mixin `mat-progress-bar-theme`
        node_modules/@angular/material/_theming.scss:2751, in mixin `angular-material-theme`
        stdin:6
      in /var/make-it.business/frontend-application/node_modules/@angular/material/_theming.scss (line 1114, column 34)
 @ ./src/styles.scss 4:14-189
 @ multi ./src/styles.scss

package.json

{
  "name": "backend-application",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "serve:development": "ng serve --environment=development -H 0.0.0.0 --port=80",
    "serve:test": "ng serve --environment=test -H 0.0.0.0 --port=80",
    "serve:staging": "ng serve --environment=staging -H 0.0.0.0 --port=80",
    "serve:production": "ng serve --environment=production -H 0.0.0.0 --port=80",
    "prepare-environment": "node ./scripts/prepare-environment.js",
    "ng": "ng",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.0.1",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/material": "^2.0.0-beta.6",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "angular2-cool-storage": "^3.0.1",
    "aos": "^2.1.1",
    "core-js": "^2.4.1",
    "flexboxgrid": "^6.3.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "^1.1.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "replace-in-file": "^2.5.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "latest"
  }
}

I faced the same issue when upgrading to material @angular/material-2 beta0.0.12

    ERROR in ./~/css-loader!./~/sass-loader/lib/loader.js!./assets/styles/app.scss
    Module build failed:
      $opacity: if($opacity == null, opacity($color), $opacity);
                                    ^
          Argument `$color` of `opacity($color)` must be a color
        Backtrace:
                node_modules/@covalent/core/common/styles/_theme-functions.scss:22, in function `opacity`
                node_modules/@covalent/core/common/styles/_theme-functions.scss:22, in function `if`
                node_modules/@covalent/core/common/styles/_theme-functions.scss:22, in function `mat-color`
                node_modules/@angular/material/_theming.scss:2143, in mixin `mat-chips-theme`
                node_modules/@angular/material/_theming.scss:3854, in mixin `angular-material-theme`
                assets/styles/_material-theme.scss:21, in mixin `custom-material-theme`

Can you show the scss file where you define the theme?
I was facing this issue because I was using wrong parameters for default, lighter and darker for some colors.

I was using:

$app-primary: mat-palette($mat-blue-grey, A700, A500, A900);

But if you go to the definition of $mat-blue-grey in _theme.scss of material, those variables are not defined, just a few have the 'A' before:

$mat-blue-grey: (
  50: #eceff1,
  100: #cfd8dc,
  200: #b0bec5,
  300: #90a4ae,
  400: #78909c,
  500: #607d8b,
  600: #546e7a,
  700: #455a64,
  800: #37474f,
  900: #263238,
  A100: #cfd8dc,
  A200: #b0bec5,
  A400: #78909c,
  A700: #455a64,
  contrast: (
    50: $black-87-opacity,
    100: $black-87-opacity,
    200: $black-87-opacity,
    300: $black-87-opacity,
    400: white,
    500: white,
    600: $white-87-opacity,
    700: $white-87-opacity,
    800: $white-87-opacity,
    900: $white-87-opacity,
    A100: $black-87-opacity,
    A200: $black-87-opacity,
    A400: white,
    A700: $white-87-opacity,
  )
);


Using only the numbers and removing the 'A' before, fixed the issue for me.

$app-primary: mat-palette($mat-blue-grey, 700, 500, 900);

That鈥檚 straight from angular material https://material.angular.io/guide/theming which is straight from the material color spec https://material.io/guidelines/style/color.html

Typical we use 100 for the lighter hue and 900 for the darker

Note to future self

This issue can occur when you pass a _theme_ map to mat-color instead of a _palette_ such as $primary (as in $primary: map-get($theme, primary);).

For example If you have

background: mat-color($theme, darker);

you need

background: mat-color(map-get($theme, primary), darker);
Was this page helpful?
0 / 5 - 0 ratings