Open BerndWessels opened 4 years ago
I'm having the same issue. Running a similar setup as OP, and the babel plugin isn't working.
My rollup.config
:
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import external from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
import url from 'rollup-plugin-url';
import svgr from '@svgr/rollup';
import pkg from './package.json';
export default {
input: 'src/index.js',
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'esm',
sourcemap: true,
},
],
plugins: [
external(),
postcss({
globalModulePaths: [/node_modules\/react-day-picker/],
}),
url(),
svgr(),
babel(),
resolve(),
commonjs(),
],
};
"babel-plugin-styled-components": "^1.10.7",
I fixed it by downgrading to version 1.10.5
. I also tried 1.10.7
and 1.10.6
but they won't work. Version 1.10.5
and 1.10.2
works (and probably anywhere in between)
TL;DR: install v 1.10.5
for a fix.
@obedparla thanks, that might be good place to start figuring out which change is breaking it.
Downgrading is not my preferred option ;) Anyways I'll have a look at those changes, but am new to the project, hopefully a more experienced maintainer than me can see the problem and fix right away.
Hey @BerndWessels I have a repro of the issue right here: https://github.com/nickhudkins/sc-repro, it certainly doesn't seem like a babel-plugin-styled-components
issue specifically, and is most likely something to do with rollup-plugin-babel
, at least... instinctively that is what I believe. I can keep digging in deeper, but a simple repro means "anyone" can dive in more easily.
It appears that as of 1.10.7, isStyled
is failing to return true
when executed with rollup:
I would guess this has something to do with how rollup is generating the AST, but I am officially out of my depth now.
More importantly: This is the offending commit:https://github.com/styled-components/babel-plugin-styled-components/commit/35a3bb7023433f17555fdeb1e966e7816d9e8f60 is the commit that broke this while using rollup
https://github.com/styled-components/babel-plugin-styled-components/pull/283 If you want to give it a try, have at it. My local project is resolved with this change
@nickhudkins, looks like your fix was reverted in v1.11.1, any chances you could revisit this?
+1 please
+1 🙏
Hey @probablyup,
This inability of isStyled
to return true
when run through roll up is causing wide set of issues similar to:
Mismatch of classnames error with react - Occurs as the browser bundle generated by rollup + babel-plugin-styled-components does not contain the displayName
and componentId
prop.
I know this issue is lying around since v1.10.6, more than a a year back when it was first introduced. Any leads would be helpful either on this plugin or with rollup 🙏
+1
+1
any updates on this?
Open to PRs, I don't have any projects using this setup so I probably won't personally be working on it.
We had bumped into this issue across both our styled-component custom ui library and our many consuming projects.
It appears this issues crept up when the following is true:
1) project that uses an external package that uses styled-components
2) external package in question is packaged with rollup
3) both project (gatsby) and external package (rollup) use anything higher than babel-plugin-styled-components@v1.10.5
The fix/workaround, was mentioned here, we just locked the version in our consuming projects and in our lib to babel-plugin-styled-components@v1.10.5
.
I've added repo branches for the fix: https://github.com/iDVB/react-components/tree/fixed https://github.com/iDVB/gatsby3_site_issue/tree/fixed
@probablyup i've created a PR detailing my investigation and proposal : ) https://github.com/styled-components/babel-plugin-styled-components/pull/327
+1
Hey, @rollup/plugin-babel looks like handles input and output in different ways. So you need two configs.
import babel, { getBabelOutputPlugin } from '@rollup/plugin-babel';
export default components.map((component) => {
return {
input: component,
output: {
file: component.replace(/\/src\//g, "/lib/"),
format: "cjs",
plugins: [
// babel for output
getBabelOutputPlugin({
filename: 'whatever.js',
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: [['babel-plugin-styled-components', { displayName: true }]],
}),
terser() ],
},
plugins: [
commonjs(),
autoExternal(),
// babel for input
babel({
exclude: "node_modules/**",
presets: ["@babel/preset-env", "@babel/preset-react"],
}),
],
};
});
Hi
I put some
console.logs
into thebabel-plugin-styled-components
and it seems to get called but for some reason it does not process and the result is that for examplecomments
andwhitespaces
are not removed from thecss templates
output, like in this resultingminified output file
:Can you see if I am doing something wrong or if there is a problem with
babel-plugin-styled-components
? Thank you.I have the following
rollup.config.js
and these are the latest dependencies: