sveltevitepostcssautoprefixer

Vite PostCSS module error when building app in Svelte


I came across this strange error in Svelte; every time I ran npm run dev, this vite error would appear:

[vite] Internal server error: Failed to load PostCSS config (searchPath: /Users/Documents/Personal projects): [Failed to load PostCSS config] Failed to load PostCSS config (searchPath: /Users/Documents/Personal projects): [Failed to load PostCSS config] Failed to load PostCSS config (searchPath: /Users/Documents/Personal projects): [Error] Cannot find module 'autoprefixer'

I'm new to vite so it took me an hour of research, to figure out how to export the module, I was able to fix it by creating a postcss.config.cjs file and inside the file add:

module.exports = {
    autoprefixer: {}
}

I hope this helps anyone that comes across the same/similar error.


Solution

  • Create postcss.config.cjs file and add:

    module.exports = {
        autoprefixer: {}
    }
    

    The reason why it wasn't building, is because svelte wasn't exporting the autoprefixer module