linaria icon indicating copy to clipboard operation
linaria copied to clipboard

CSS not apply to elements in V6 with Next.js

Open mydearxym opened this issue 1 year ago • 5 comments

hi team,

recently i try to replace styled-component with linaria, but css seems not work.

Environment

minimal Nextjs@14 with latest Linaria@6

  • Linaria version: 6.0.0
  • Bundler (+ version): webpack@5
  • Node.js version: v20.3.1
  • OS: Mac

.babelrc:

{
  "presets": ["next/babel", "@wyw-in-js"],
  "plugins": []
}

wyw-in-js.config.js

module.exports = {
  evaluate: true,
  displayName: true,
};


next.js config

const withLinaria = require("next-with-linaria");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const nextConfig = {
  webpack: (config, options) => {
    config.plugins.push(new MiniCssExtractPlugin());
    config.module.rules.push(
      {
        test: /\.ts?$/,
        use: [
          {
            loader: "@wyw-in-js/webpack-loader",
          },
        ],
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, "css-loader"],
      }
    );

    return config;
  },
};

module.exports = withLinaria(nextConfig);

related packages:

  "dependencies": {
    "@linaria/core": "^6.0.0",
    "@linaria/react": "^6.0.0",
    "next": "14.0.4",
    "next-with-linaria": "^0.6.0",
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "@wyw-in-js/babel-preset": "^0.2.2",
    "@wyw-in-js/webpack-loader": "^0.2.2",

Description

project is running, but seems Linaria only recognized element tag, the CSS rules are not apply to it

image

image

Reproducible Demo

https://github.com/groupher/wyw-demo

mydearxym avatar Dec 12 '23 02:12 mydearxym

Am facing the same issue with Next 14. Commenting to follow

harumijang avatar Jan 11 '24 19:01 harumijang

Anyone solved this yet? Would be great to see a reference implementation.

JonCognioDigital avatar Apr 15 '24 13:04 JonCognioDigital

Was only able to get it with page routing and next.js 14 using https://www.npmjs.com/package/next-with-linaria. Once I started to use app routing, this method no longer worked. I ended up switching Linaria over to Emotion. Implementation and import names are compatible so there was almost zero re-work. I know the bundle size implication of Emotion but due to the variety of our components (small), we chose to eat the cost as a trade-off for next.js 14 compatibility. I would have liked to have both but it's not within my pay grade to ensure compatibility between the two.

victor-bts avatar Jun 26 '24 15:06 victor-bts

anyone can work with next 14 app router and linaria?

straxico avatar Jul 22 '24 13:07 straxico

I think there needs to be an SWC plugin. There was one but currently outdated: https://github.com/arendjr/linaria-swc

aberba avatar Jul 29 '24 18:07 aberba