Skip to content
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

svelte(css-syntax-error) when using postcss-preset-env custom media #517

Closed
shamsartem opened this issue Sep 2, 2020 · 8 comments
Closed
Labels
question Further information is requested

Comments

@shamsartem
Copy link

To Reproduce
You can use my repo to reproduce it https://github.com/shamsartem/dbudget
Check default.svelte for errors.

Alternatively:

  1. Add postcss-preset-env plugin to rollup.config.js and to postcss.config.js with { stage: 0 } setting
  2. Add e.g. @Custom-Media --t (width >= 768px); in App.svelte inside style tag with lang="postcss"
  3. Try using @media (--t) in App.svelte - it should work and there is no error visible
  4. Try using @media (--t) in some other component - it shows the error but builds and works correctly

Expected behavior
There shouldn't be an error in this case

System (please complete the following information):

  • OS: Manjaro
  • IDE: VSCode
  • Plugin/Package: "Svelte for VSCode"
@shamsartem shamsartem added the bug Something isn't working label Sep 2, 2020
@jasonlyu123
Copy link
Member

Duplicate of #305

We don't have a plan to support the validation of postcss or css next. That's too much maintenance works. You can refer to this doc for setup instruction

@dummdidumm
Copy link
Member

For your specific case: Svelte files are transpiled per-file, so it does not know anything about that --t inside the component if you don't define it in there. I think it works for your build because everything is bundled to one big css in the end.

@dummdidumm dummdidumm added question Further information is requested and removed bug Something isn't working labels Sep 3, 2020
@shamsartem
Copy link
Author

Thank you very much for the response. I really appreciate your effort on this

I decided to post about this only because previously for a couple of weeks I'v been using those custom media queries and there was no error but after some update (I suppose) now there is one. Also this could become part of css spec in the future, who knows. I hope it will at least be fixed then. Thanks

@jasonlyu123
Copy link
Member

You need to somehow make the custom-media from media-queries.css also available from the preprocess of svelte-config.js.

@shamsartem
Copy link
Author

shamsartem commented Sep 4, 2020 via email

@jasonlyu123
Copy link
Member

Sorry for that I found it doesn't work XD

@jasonlyu123
Copy link
Member

jasonlyu123 commented Sep 4, 2020

I found a workaround (hope I didn't jump to the conclusion too fast again lol)

// svelte.config.js
const sveltePreprocess = require('svelte-preprocess')
const fs = require('fs')
const mediaQueries = fs
  .readFileSync('./src/assets/css/media-queries.css')
  .toString()

module.exports = {
  preprocess: sveltePreprocess({
    postcss: {
      prependData: mediaQueries,
    },
  }),
}

About the build, I guess it's because you declare the custom-media in your app.svelte. Once I remove it and restart the dev server the same error you encounter in the IDE appears.
Maybe you can import the media-queries when you want to use it, or make it globally available.

@shamsartem
Copy link
Author

@jasonlyu123 You are just amazing! You solved both issues in one go (having media queries in two places wasn't great as well). I really appreciate this, now I can work with pleasure. Thanks again and good luck in everything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants