Skip to content

postcss-custom-properties warnings when overriding css variables #7991

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
Morente5 opened this issue Oct 10, 2017 · 17 comments
Closed

postcss-custom-properties warnings when overriding css variables #7991

Morente5 opened this issue Oct 10, 2017 · 17 comments
Labels
freq1: low Only reported by a handful of users who observe it rarely P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity2: inconvenient type: bug/fix

Comments

@Morente5
Copy link

Morente5 commented Oct 10, 2017

Bug Report

From Issue #7514
Related to PR #7712

Versions.

Angular CLI: 1.5.0-rc.0
Node: 8.1.2
OS: win32 x64
Angular: 5.0.0-rc.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0-rc.0
@angular-devkit/build-optimizer: 0.0.25
@angular-devkit/core: 0.0.17
@angular-devkit/schematics: 0.0.30
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.0.41
typescript: 2.5.3
webpack: 3.7.1

The log given by the failure.

A lot of warnings are being shown to me since #7712 :

WARNING in ./path/to/component/some-component.component.scss
(Emitted value instead of an instance of Error) postcss-custom-properties: path\to\component\some-component.component.scss: Custom property ignored: not scoped to the top-level :root element (some-css-selector { ... --custom-property: ... })
    at Object.emitWarning (path-to-my-project\node_modules\webpack\lib\NormalModule.js:117:16)
    at path-to-my-project\node_modules\postcss-loader\index.js:131:24
    at Array.forEach (native)
    at path-to-my-project\public\node_modules\postcss-loader\index.js:130:31
    at <anonymous>

Repro steps.

when I set:

:root {
  --custom-property: 200; 
}

on styles.scss,
and I override it in a component, some-component.scss

some-css-selector {
  --custom-property: 100; 
}

It's working perfectly fine but it's very annoying seeing a warning for each css variable I override.

May that be related to a postcss-custom-properties limitation?

@filipesilva filipesilva assigned filipesilva and Brocco and unassigned filipesilva Oct 16, 2017
@filipesilva filipesilva added freq1: low Only reported by a handful of users who observe it rarely P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity2: inconvenient type: bug/fix labels Oct 16, 2017
@renestalder
Copy link

postcss-custom-properties doesn't support variable declarations on CSS selectors other than :root. Only :root is allowed. That's why you get the warning. Mostly this only means that your variable will not be transpiled back for older browsers. So when you want this to work with older browsers, you have to use :root all the time, so postcss-custom-properties knows what to do with it.

@adrm
Copy link

adrm commented Oct 30, 2017

Is there a way to silence this warning or noting to the tool that I don't care about transpiling this feature back to older browsers? Thanks.

@renestalder
Copy link

I don't know about the angular-cli and how it can be configured with it (you have to check by yourself), but the setting of the postcss-custom-properties package you'll find here:
https://github.com/postcss/postcss-custom-properties#warnings

@darrenmothersele
Copy link

We need a way to add custom PostCSS config to Angular CLI projects.

This issue is related: Using the Bulma CSS library current causes lots of warnings:
jgthms/bulma#1190

@jycouet
Copy link

jycouet commented Nov 6, 2017

Hi,
In my project, by design, we have a lot of css variables.
How should I get rid of these warnings?

Thank you for your support 👍

@mgmarlow
Copy link

mgmarlow commented Nov 7, 2017

Not using Bulma, but running into the same issue since our project doesn't care about older browsers. We really don't want to eject the webpack configuration at this point, so can we can an extra configuration setting or expose the postcss configuration to get rid of these warnings?

@calebeaires
Copy link

Same here with bulma when calling sass! Does anyone has find an way to fix it?

@zoonman
Copy link

zoonman commented Nov 11, 2017

I think fix explained here MoOx/postcss-cssnext#186 but we need a way to deliver to Angular.

@jycouet
Copy link

jycouet commented Nov 11, 2017

Thank you @zoonman for the update! :)
How to put this part of angular-cli? That is the question.

@zoonman
Copy link

zoonman commented Nov 12, 2017

@jycouet I believe it has to be a part of .angular-cli.json file, but I don't know how to declare config and pass that declaration inside.
I'm newbie in the modern Angular world (I mean 2.+). I noticed there is an eject.d.ts file inside @angular/cli/tasks which exports postcssArgs. So we need someone like @Brocco, who knows Angular implementation really well.
In my case error looks like this:

WARNING in ./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader?{"ident":"postcss"}!./node_modules/stylus-loader?{"sourceMap":false,"paths":[]}!./src/styles.styl
(Emitted value instead of an instance of Error) postcss-custom-properties: /Users/zoonman/Projects/www/liverecord/client/src/styles.styl:115:3: Custom property ignored: not scoped to the top-level :root element (.default :root { ... --body-color: ... })
NonErrorEmittedError: (Emitted value instead of an instance of Error) postcss-custom-properties: /Users/zoonman/Projects/www/liverecord/client/src/styles.styl:115:3: Custom property ignored: not scoped to the top-level :root element (.default :root { ... --body-color: ... })
    at Object.emitWarning (/Users/zoonman/Projects/www/liverecord/client/node_modules/webpack/lib/NormalModule.js:117:16)
    at /Users/zoonman/Projects/www/liverecord/client/node_modules/postcss-loader/index.js:131:24
    at Array.forEach (<anonymous>)
    at /Users/zoonman/Projects/www/liverecord/client/node_modules/postcss-loader/index.js:130:31
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
 @ ./src/styles.styl 4:14-186
 @ multi ./src/styles.styl ./node_modules/font-awesome/css/font-awesome.css

I found that error is coming from postcss but there in no way to change its config.
Looks like this was planned #5701 but it I don't know anything more. I can't say more, I'm newbie, I just started with this new version of Angular.

@trimox
Copy link

trimox commented Nov 21, 2017

Found a hackable workaround.

As there is no "official" way to provide Angular CLI a postcss-custom-properties config - yet.

Open index.js from your projects node_modules\postcss-custom-properties\dist folder
Find this line:
warnings: options.warnings === undefined ? true : options.warnings,

We're going to change warnings property from true to false.
warnings: options.warnings === undefined ? false : options.warnings,

Save and run ng serve
image

@eitanfr
Copy link

eitanfr commented Nov 23, 2017

@trimox thx it works, until there will be a fix or a way to pass options to postcss-custom-properties I add hacked postcss-custom-properties to my project and used it as local package.

@ryzy
Copy link

ryzy commented Nov 24, 2017

If you don't want to eject from ng and you can afford not having postcss-custom-properties postprocessor at all (e.g. because you don't support older browsers anyway), you can remove it completely with a little command like the one below.

I add it to my package.json scripts entry and run as a postinstall script, so it runs always after you do any changes in installed packages. It removes each line where customProperties occurs in the above webpack config. Tested with angular-cli 1.5.

"scripts": {
  "remove-postcss-custom-properties": "sed -i -E '/customProperties/s/^.*$//g' node_modules/@angular/cli/models/webpack-configs/styles.js",
}

Hack-ish, I know... but might do as a temp solution, while we decide what do we want to do with these custom properties and backward support.

@calebeaires
Copy link

@ryzy After put this line on script and run it manually, the warnings does nos desapear. May you explain how to entirely implement it?

@clydin
Copy link
Member

clydin commented Dec 14, 2017

Closing as #8289 has a more up to date discussion on the issue.

@clydin clydin closed this as completed Dec 14, 2017
@briancmpbll
Copy link

What is the workaround for adding postcss-custom-properties support now? We needed this and had it working, albeit in a hacky way, for our IE support, and now it is gone with no official alternative besides rolling back to before this pr was merged.

@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 7, 2019
@clydin clydin removed their assignment Jun 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
freq1: low Only reported by a handful of users who observe it rarely P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity2: inconvenient type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.