When setting up Panda CSS in a RedwoodJS project, I ran into a small issue: although autocomplete worked fine in my editor, the dev server couldnât find the generated Panda files, so the styles werenât applied.
The solution
The solution is quite simple, if you know that the keyword to search for is resolve
!
I ended up finding it in this StackOverflow answer. Note that the accepted answer is out of date and only adds unnecessary steps.
All you need to do is add the following highlighted lines to your Vite config.
const viteConfig: UserConfig = {
plugins: [redwood()],
resolve: {
alias: [
{
find: 'styled-system',
replacement: resolve(__dirname, 'styled-system'),
},
],
},
};
This tells Vite to find imports starting with styled-system
, in the same folder as Viteâs config.
Explanation
By default, Viteâs entry point in a RedwoodJS project is in web/src
, so the bundler has no awareness of whatâs at the root level (web
). The resolve
alias maps styled-system
imports to the correct location, fixing the issue.