1

I'm trying to get PostCSS set up in my SvelteKit project to start playing with container queries. I installed 'svelte-preprocess' in my svelte.config.js file and made a postcss.config.cjs file (see below)

svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import sveltePreprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: sveltePreprocess({ postcss: true }),
    kit: {
        adapter: adapter(),
    },
};

export default config;

postcss.config.cjs

const postcssPresetEnv = require('postcss-preset-env');

const config = {
    plugins: [
        postcssPresetEnv({
            stage: 3,
            features: {
                'nesting-rules': true,
                'custom-media-queries': true,
                'media-query-ranges': true,
            },
        }),
    ],
};

module.exports = config;

I get the following error at my root level +page.svelte file:

*")" is expected

If you expect this syntax to work, here are some suggestions: If you use less/SCSS with svelte-preprocess, did you add lang="scss"/lang="less" to your style tag? If you use SCSS, it may be necessary to add the path to your NODE runtime to the setting svelte.language-server.runtime, or use sass instead of node-sass. Did you setup a svelte.config.js? See https://github.com/sveltejs/language-tools/tree/master/docs#using-with-preprocessors for more info.*

Here's my +page.svelte file html and css (I'm trying to learn the container query syntax)

<div class="displayContainer">
    <div class="queryWrapper">
        <div class="imgWrapper">
            //custom image component goes here
        </div>
        <div class="summaryContainer">
            <h2>sample header text</h2>
            <p>
               sample paragraph text
            </p>
                </div>

    </div>
</div>

<style lang="postcss">
    .displayContainer {
        container: homeDisplay / inline-size;
    }
    .queryWrapper {
        @container homeDisplay (min-width: 450px) { /*line with error*/
            display: grid;
            grid-template-column: 350px 1fr;
            gap: 20px;
        }
    }
    .summaryContainer {
        max-width: 600px;
    }
</style>

package.json file

{
    "name": "algomancy-site",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "dev": "vite dev",
        "build": "vite build",
        "preview": "vite preview",
        "lint": "prettier --plugin-search-dir . --check . && eslint .",
        "format": "prettier --plugin-search-dir . --write ."
    },
    "devDependencies": {
        "@sveltejs/adapter-auto": "^1.0.0",
        "@sveltejs/kit": "^1.0.0",
        "@types/postcss-preset-env": "^8.0.0",
        "eslint": "^8.28.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-plugin-svelte3": "^4.0.0",
        "postcss-load-config": "^4.0.1",
        "postcss-preset-env": "^8.0.1",
        "prettier": "^2.8.0",
        "prettier-plugin-svelte": "^2.8.1",
        "svelte": "^3.54.0",
        "svelte-preprocess": "^5.0.1",
        "vite": "^4.0.0"
    },
    "type": "module"
}

It's expecting a ")" after min-width.

I searched the documentation and recommended GitHub repos for preprocess configuration. Many of these resources/blogs reference a rollup.config.js file.

I don't see a rollup.config.js file in my skeleton SvelteKit project or in the SvelteKit documentation.

Is my issue from lacking a rollup file or is there an error in my file setup above?

joshCode25
  • 23
  • 5
  • I don't think `lang="postcss"` is required. SvelteKit uses Vite which internally uses Rollup, if you need to set Rollup options, you can [set those in the Vite config](https://vitejs.dev/config/build-options.html#build-rollupoptions). – H.B. Feb 09 '23 at 12:39
  • When I remove lang="postcss", it tells me container is an unknown property. It's my understanding SvelteKit doesn't support container queries yet, but postcss allows them to be used in SvelteKit. – joshCode25 Feb 10 '23 at 02:46
  • Then I simply remember that wrong, thought that PostCSS would also apply to other pre-processed languages and thus would not appear explicitly in `lang`. – H.B. Feb 10 '23 at 07:18

1 Answers1

1

After further digging I found this is a known issue with Svelte's compiler has with the '@container' syntax and is being worked on. Github issue 6969

A simple work-around is to place container queries (@container ...) in a separate .css file and import it where needed.

joshCode25
  • 23
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 22 '23 at 04:46