I wanted to give Linaria (utilizing next-linaria) a try, but I'm currently stuck to get it working in any of my Next.js projects (that also use Typescript by the way).
The root of evil seems to be path aliases that are supported by Next.js by default.
tsconfig.json
...
"compilerOptions": {
...
"paths": {
"~/*": [
"src/*"
]
}
},
When just installing Linaria and next-linaria, I get an error like this:
Error: Can't resolve '~/layout/main/MainWrapper' in '[...]\src\layout\main'
I already know that Linaria stated to not support any other module aliasing than @babel-plugin-module-resolver or webpack. However, I can't get either of those to work.
I tried @babel-plugin-module-resolver and put same path configuration (and some other tries) to .babelrc without success.
"plugins": [
["module-resolver", {
"alias": {
"~/*": [
"src/*"
]
}
}]
]
I also tried doing the same with webpack aliases.
next.config.js
module.exports = withLinaria({
webpack: (config, { dev }) => {
config.resolve.alias = {
...config.resolve.alias,
"~/": path.resolve(__dirname, "./src/"),
};
return config;
},
});
The default project structure of Next.js looks like this:
/
/pages (contains entry points for each route)
/src (contains regular react components)
So, I'm kindly asking if anyone can tell us how to use path aliasing with Next + Linaria.