Reputation: 2438
When attempting to transpile the Spacing.js
file, it results in an undefined import even when styled-components
was seemingly being imported and used (in the same way) successfully in other files. Even when removing the styled-components babel plugin, a similar error occurs.
.babelrc
{
"presets": [["es2015", { "modules": false }], "react-native"],
"plugins": [
["styled-components", { "displayName": true }],
"react-hot-loader/babel",
"react-native-web",
"transform-decorators-legacy",
"transform-class-properties"
],
"env": {
"production": {
"plugins": [
"transform-react-inline-elements",
"transform-react-constant-elements"
]
}
}
}
Spacing.js
- Code before transpilation
import React, { Component, Node } from "React";
import styled from "styled-components";
type Props = {
size: string,
color: string,
fullWidth?: boolean
};
class SpacingComponent extends Component<Props> {
render(): Node {
const { size, color, fullWidth = false } = this.props;
return <Spacing size={size} color={color} fullWidth={fullWidth} />;
}
}
const Spacing = styled.View`
height: ${props => props.size}px;
background-color: ${props => props.color || "transparent"};
width: ${props => {
return props.fullwidth ? "100%" : props.size + "px";
}};
`;
export default SpacingComponent;
styled-components
styled-components
library (v3.2.5)Another example can be seen when removing the styled-components
babel plugin from the babelrc, thus the withConfig is not added.
styled-components
babel pluginIs babel or webpack adding .default
when it doesn't need to, if so, how could I investigate why?
Upvotes: 6
Views: 8877
Reputation: 31
Not sure if this is going to be helpful to anyone but for me the same error was triggered like this style.something
and fixed using an html element eg style.span
Upvotes: 2