Closed rogadev closed 2 years ago
Can you provide a reproduction in a repository form? Not sure what you tried but I didn't see the error following the guide of tailwindcss. Do you use svelte-kit, vite template or rollup template?
As for stylelint, We have two sources for CSS diagnostic. One is from the svelte compiler and the other is vscode-css-languageservice. Stylelint can help to replace the latter. But your problem is with the former.
I use Vite.
I've made the repo public, you can find it here. You can find the component in question in src/lib/components/Navbar.svelte
.
I agree, I believe the problem is with the former as well. I really hope I'm just missing some silly config setting. Surely other people use these modifiers in the same way... It's more than a little suspicious that (it seems) no one else online has have run into this problem. š¤·āāļø Please let me know if you find anything. I greatly appreciate your time.
Looks like it's https://github.com/sveltejs/language-tools/issues/1394. You probably open the editor in the repo root where the process.cwd is not the same as your build. So postcss and tailwind can't find the config file. We can probably add the solution for that issue to the tailwind CSS troubleshooting docs.
I updated postcss.config.cjs
as shown in #1394 but the same problem occurs.
// postcss.config.cjs
const autoprefixer = require('autoprefixer')
const path = require('path')
const tailwindcss = require('tailwindcss')
module.exports = {
plugins: [
tailwindcss(path.resolve(__dirname, './tailwind.config.cjs')),
autoprefixer,
],
}
Okay well this is interesting...
When you create a Svelte project it wants you to put it in a folder. So I did that (svelte/
). Then built my project from there.
I just now pulled it out of the svelte folder to live in the root of my repo. Like magic, the error message has gone. I tried this because you mentioned "You probably open the editor in the repo root where the process.cwd is not the same as your build." Can you explain a bit more about that?
Here's a short video that explains why I feel this is an issue, not just a documentation problem: https://youtu.be/8ZXwklVjKzg
TL:DNR - What if I wanted several svelte kit projects inside the same repo? None of them could use Tailwind CSS this way without getting errors that aren't really errors? Is this a Svelte problem or a Tailwind problem?
The original author of that issue said it would be fine to not pass posscss.config.cjs path to svelte-preprocess. But that doesn't work for me. I only manage to make it work when the config path is passed into the svelte-preprocess as an option. If you set it properly it should also work in monorepo.
import preprocess from 'svelte-preprocess';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url));
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess({
postcss: {
configFilePath: join(__dirname, 'postcss.config.cjs')
}
}),
// ... your other options
};
export default config;
I tried this because you mentioned "You probably open the editor in the repo root where the process.cwd is not the same as your build." Can you explain a bit more about that?
When VSCode is opened with a directory the process for it and its child process default to set its working directory to that directory. This means all the relative path is resolved from that path. Tailwind and postcss assume that it'll always be opened in a process where the config file is in the root of the process working directory. But it's not the case for us to run the preprocess. So they can't find the config file.
We could maybe change the cwd with process.chdir But since the preprocess is asynchrony I really don't know if it would cause any problem. So I would say maybe it's better to document it or even ask if postcss load config and tailwind plugin if they could factor that in.
Describe the bug
When I try to do the following:
My IDE throws an error at the first occurrence of
:
in the string.It seems that Svelte thinks this is a "css-syntax-error", however the
lang
property on my style block is clearly set to "postcss". Furthermore, Tailwind is correctly handling and applying these styles. You can even see that the Tailwind CSS extension is picking up that this is a hover modifier and displays the correct tooltip accordingly.Reproduction
Create the following component and put it in your main view.