babel-plugin-styled-components: styled.keyframes.withConfig is not a function
Reopening https://github.com/styled-components/babel-plugin-styled-components/issues/213 as I’m still experiencing this issue despite the suggestion provided.
I’m using v3.4.10 of styled-components and v1.10.0 of babel-plugin-styled-components. This is what I’m using in my component :
import styled, { keyframes } from 'styled-components'
const rotate = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`
This is bundled (wrongly ?) into the following :
var rotate = styled.keyframes(['from{transform:rotate(0deg);}to{transform:rotate(360deg);}']);
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 12
- Comments: 22 (5 by maintainers)
Commits related to this issue
- fix: workaround styled-components + jest issue https://github.com/styled-components/babel-plugin-styled-components/issues/216#issuecomment-516941240 — committed to mll-lab/react-components by spawnia 2 years ago
- chore(release): 8.1.1-alpha.1 [skip ci] ## [8.1.1-alpha.1](https://github.com/mll-lab/react-components/compare/v8.1.0...v8.1.1-alpha.1) (2022-02-21) ### Bug Fixes * workaround styled-components + j... — committed to mll-lab/react-components by semantic-release-bot 2 years ago
- fix: workaround styled-components + jest issue https://github.com/styled-components/babel-plugin-styled-components/issues/216#issuecomment-516941240 — committed to mll-lab/react-components by spawnia 2 years ago
- chore(release): 8.1.1 [skip ci] ## [8.1.1](https://github.com/mll-lab/react-components/compare/v8.1.0...v8.1.1) (2022-02-23) ### Bug Fixes * workaround styled-components + jest issue ([3ba7518](htt... — committed to mll-lab/react-components by semantic-release-bot 2 years ago
Following up on my comment above, my team and I are using this workaround to avoid the
styled.keyframes.withConfig is not a function
error:View source for ‘Spinner’ component
It’s strange having to mix ES2015
import
and CommonJSrequire
in the same file. However, when we build our component using Rollup using the syntax above, we no longer see the error in our Jest tests. Errors would appear when components consuming our ‘Spinner’ component would runkeyframes
from our CommonJS export of Spinner. Here is the CommonJS export of Spinner, which contains the following lines:It’s possible that Rollup’s
_interopDefault
method is only fetching the default export, which could explain why the error in question gets thrown. I haven’t had an opportunity to dig further, but I’ll follow up once I do.Ran in to this issue (again) after updating a bunch of dependencies and our rollup babel plugin after migrating to React 17.
The above solution worked in our NextJS app loading a component library that included a keyframe import from styled-components.
Thanks again for this @theetrain 🙏
Hi, we’re also experiencing this issue. When we run Jest on “Component A” that is consuming “Component B” built with babel, we see the following output:
styled.keyframes.withConfig is not a function
👀 See source code:
keyframes
This is what I’m using. Also, is support for styled components v4 still in active development?
Seeing a very similar issue when trying to run jest:
Still trying to determine if this is specific to something in my environment, though.
I had a similar error related to
styled-components
andtypescript-plugin-styled-components
(which extends from babel-plugin-styled-components).As I was using the
typescript-plugin-styled-components
to add readable classnames to the DOM whilst developing (related to this thread; https://github.com/styled-components/styled-components/issues/976), I got this error;The error was resolved when downgrading
typescript-plugin-styled-components
to1.0.0
.Leaving this here for anyone else googling the same keywords I did ^^
How are you importing styled? keyframes is a named export so you have to bring it in like this: