question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support constant() and env()

See original GitHub issue

Hey there,

in my build setup (optimize-css-assets-webpack-plugin using cssnano) I had to disable postcss-calc because it was killing any calc() that use constant() and env() (see Designing Websites for iPhone X). Note how the 100% turned into 1:

Input

body {
  height: 100%;
  /* iPhone X on iOS 11.0 */
  height: calc(100% + constant(safe-area-inset-top) + constant(safe-area-inset-bottom));
  /* iPhone X on iOS 11+ */
  height: calc(100% + env(safe-area-inset-top) + env(safe-area-inset-bottom));
}

Output

body {
  height: 100%;
  height: calc(1 + constant(safe-area-inset-top) + constant(safe-area-inset-bottom));
  height: calc(1 + env(safe-area-inset-top) + env(safe-area-inset-bottom))
}

I tried producing a minimal test case with only postcss-calc, but all I got was:

➜  node index.js
/…/post-css-calc/node_modules/postcss/lib/lazy-result.js:280
            throw error;
            ^

Error: Parse error on line 1:
100% + constant(safe-area-i
-------^
Expecting 'SUB', 'LPAREN', 'NESTED_CALC', 'NUMBER', 'CSS_VAR', 'LENGTH', 'ANGLE', 'TIME', 'FREQ', 'RES', 'EMS', 'EXS', 'CHS', 'REMS', 'VHS', 'VWS', 'VMINS', 'VMAXS', 'PERCENTAGE', got 'PREFIX'
    at Parser.parseError (/…/post-css-calc/node_modules/reduce-css-calc/dist/parser.js:160:21)
    at Parser.parse (/…/post-css-calc/node_modules/reduce-css-calc/dist/parser.js:226:22)
    at /…/post-css-calc/node_modules/reduce-css-calc/dist/index.js:35:30
    at walk (/…/post-css-calc/node_modules/postcss-value-parser/lib/walk.js:15:13)
    at ValueParser.walk (/…/post-css-calc/node_modules/postcss-value-parser/lib/index.js:18:5)
    at exports.default (/…/post-css-calc/node_modules/reduce-css-calc/dist/index.js:29:51)
    at transformValue (/…/post-css-calc/node_modules/postcss-calc/dist/lib/transform.js:24:45)
    at exports.default (/…/post-css-calc/node_modules/postcss-calc/dist/lib/transform.js:54:100)
    at /…/post-css-calc/node_modules/postcss-calc/dist/index.js:28:52
    at /…/post-css-calc/node_modules/postcss/lib/container.js:144:26

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
natizcommented, Aug 31, 2018

+1

1reaction
MarvinXucommented, Aug 8, 2018

does disabling postcss-calc work? I am trying to find a fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

env() - CSS: Cascading Style Sheets - MDN Web Docs
The env() CSS function can be used to insert the value of a user-agent defined environment variable into your CSS, in a similar...
Read more >
CSS Environment Variables env() | Can I use... Support tables ...
"Can I use" provides up-to-date browser support tables for support of ... CSS Environment Variables env() ... 1 Supported as constant() instead of...
Read more >
What is CSS constant() used for? - Stack Overflow
I believe constant() was a precursor to env() in the draft spec for environmental variables. You should just use env moving forward and ......
Read more >
Should all .env constants be listed in your config/*.php files?
I'm interested is it considered best practice not to use env() through your class files for constants that are not in the default...
Read more >
An Introduction to Environment Variables and How to Use Them
Service account names. What these have in common are their data values change infrequently and the application logic treats them like constants, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found