Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS prop is breaking build when component comes from imported object #240

Closed

Comments

@dlehmhus
Copy link

Problem

When trying to add css to a component that comes from a different file from inside an object, an error gets thrown with the message Uncaught ReferenceError: Icons is not defined. Strangely the error only occurs in the production build. In development-mode everything is working fine. Also when I move the content of the icons.tsx inside the app.tsx everything is working as expected as well.

Setup

// icons.tsx
import React from "react";

const icons = { Foo: (props: any) => <div {...props}>Foo</div> };

export default icons;
// app.tsx
import React from "react";
import { css } from "styled-components/macro";
import Icons from "./icons";

const someCss = css` background: purple;`;

const App: React.FC = () => { return <Icons.Foo css={someCss} />; };

Repo with an example setup: https://github.com/dlehmhus/styled-components-with-macro-example

@sfishel-splunk
Copy link

Any updates on this? I just ran into it myself. Looks like it was introduced in 1.9.0, so reverting to 1.8.0 is the only workaround I can find.

@chasemccoy
Copy link

Also seeing this behavior

sfishel18 added a commit to sfishel18/babel-plugin-styled-components that referenced this issue Aug 19, 2020
this makes sure that other babel transformations that rename variables will be able to process the ast nodes created by this plugin

fixes styled-components#240
@sfishel18
Copy link
Contributor

Looks like the root cause is the JSX member expression, so I think you should be able to work around it like this:

import React from "react";
import { css } from "styled-components/macro";
import Icons from "./icons";

const someCss = css` background: purple;`;

const IconFoo = Icon.Foo;
const App: React.FC = () => { return <IconFoo css={someCss} />; };

@vedrani
Copy link

vedrani commented Nov 15, 2020

Guys, any news when this could be fixed. PR is working.
What needs to be done and can I help to deliver this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment