question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

babel-plugin-emotion@10.0.13 is broken

See original GitHub issue

Hello,

After upgrading babel-plugin-emotion to the lastest version (10.0.13), we noticed that our build was broken.

After some investigation 🕵️‍♂️ , we noticed that we use a special syntax that makes the plugin to crash during the build step. Here is an example (you can see a complete example in the reproduction repository)

import { css } from "emotion"
import cn from "classnames"

function CustomComponent({someBoolean}) {
    return (
        <div
            className={cn("static classname", {
                [css({ padding: 10 })]: someBoolean,
            })}
        >
            Hello World
        </div>
    )
}

It seems to occur when we use the css function as a computed key of an object.

Here is the message thrown in the console when running yarn build on the reproduction repository:

$ yarn build 
yarn run v1.16.0
$ node scripts/build.js
Creating an optimized production build...
Failed to compile.

./src/App.js
TypeError: Cannot read property 'charAt' of undefined
    at Array.forEach (<anonymous>)
    at Array.forEach (<anonymous>)


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The output of our real project is slightly more verbose, can help to debug:

Module build failed (from ./node_modules/babel-loader/lib/index.js):
    TypeError: Cannot read property 'charAt' of undefined
        at getIdentifierName (/xxxxx/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.dev.js:286:22)
        at getLabelFromPath (/xxxxx/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.dev.js:206:19)
        at transformExpressionWithStyles (/xxxxx/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.dev.js:468:19)
        at /xxxxx/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.dev.js:589:43
        at Array.forEach (<anonymous>)
        at /xxxxx/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.dev.js:581:48
        at Array.forEach (<anonymous>)
        at macro (/xxxxx/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.dev.js:567:29)

I think the bug was introduced in this commit: https://github.com/emotion-js/emotion/commit/7bad392c3dccacb1d9adcaba63438d21030b9fd1#diff-8845e5e5474dfc2bb6c485679ab9dce3

For now, we downgraded babel-plugin-emotion.

To reproduce:

Here is a reproduction repository: https://github.com/titouancreach/babel-plugin-emotion-repro. It was created with create-react-app, then I ejected to be able to add babel-plugin-emotion. You can find the crash by building the project using yarn build.

Version of packages:

  • React: 16.8.6 (latest)
  • Emotion: 10.0.9 (latest)
  • babel-plugin-emotion: 10.0.13 (latest)

Thank you very much!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
titouancreachcommented, Jun 27, 2019
0reactions
titouancreachcommented, Sep 2, 2019

Thanks @JSteunou

Read more comments on GitHub >

github_iconTop Results From Across the Web

@emotion/babel-plugin - npm
A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.. Latest version: 11.10.5, last published: 2 months ...
Read more >
@emotion/hash | Yarn - Package Manager
:boom: Breaking Change ... The css prop doesn't work via the babel plugin. jsx can be manually imported from @emotion/core (which can be...
Read more >
https://raw.githubusercontent.com/elastic/kibana/m...
... "11.10.2" resolved "https://registry.yarnpkg.com/@emotion/babel-plugin/-/babel-plugin-11.10.2.tgz#879db80ba622b3f6076917a1e6f648b1c7d008c7" integrity ...
Read more >
the `@emotion/core` package has been renamed to ... - You.com
gatsbyjs/gatsbygatsby-plugin-emotion: emotion 11#28063 ... of which has just released a major version update with breaking changes to the package's naming.
Read more >
Module not found: Error: Can't resolve '@emotion/styled/base ...
The @emotion/babel-plugin needs to be enabled as the top most plugin in your .babelrc file. you have: "plugins": ["react-hot-loader/babel", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found