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

@babel/plugin-transform-react-constant-elements produces invalid code #11060

Closed
Pyrolistical opened this issue Jun 5, 2020 · 5 comments
Closed

Comments

@Pyrolistical
Copy link
Contributor

Pyrolistical commented Jun 5, 2020

Describe the bug
@babel/plugin-transform-react-constant-elements pulls up static jsx into an import statement resulting in invalid code

To Reproduce
https://github.com/Pyrolistical/bad-storybook-with-babel-plugin-transform-react-constant-elements
Run

npm install
npm run storybook

Error

ERROR in ./src/index.js 2:19
Module parse failed: Unexpected keyword 'var' (2:19)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import React from 'react';
> import Imported, { var _ref = /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Imported, null)); } from './imported';
| export default (function () {
|   return _ref;
 @ ./src/stories.js 2:0-27 7:44-53
 @ . sync ^\.\/(?:(?:|\/|(?:(?:(?!(?:|\/)\.).)*?)\/)stories\.js)$
 @ ./.storybook/generated-entry.js
 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/generated-entry.js (webpack)-hot-middleware/client.js?reload=true&quiet=true

Expected behavior
Storybook starts without error
System:

Environment Info:

  System:
    OS: macOS 10.15.5
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 12.16.3 - ~/.nodenv/versions/12.16.3/bin/node
    npm: 6.14.4 - ~/.nodenv/versions/12.16.3/bin/npm
  Browsers:
    Chrome: 83.0.4103.97
    Safari: 13.1.1
  npmPackages:
    @storybook/react: 5.3.19 => 5.3.19

Additional context
Related cases

Workaround

If you remove @babel/plugin-transform-react-constant-elements out of the storybook webpack config, it works
https://github.com/Pyrolistical/bad-storybook-with-babel-plugin-transform-react-constant-elements/blob/master/.storybook/main.js#L8-L11

@Pyrolistical
Copy link
Contributor Author

This is a pointless optimization plugin that should not be included as part of the storybook webpack config

@shilman
Copy link
Member

shilman commented Jun 6, 2020

@ndelangen what's your take?

@ndelangen
Copy link
Member

OK, we can remove it, @Pyrolistical would you be able to open a PR?

@Pyrolistical
Copy link
Contributor Author

@ndelangen the pr is up

ndelangen added a commit that referenced this issue Jun 9, 2020
…form-react-constant-elements

removed @babel/plugin-transform-react-constant-elements fixes #11060
@shilman
Copy link
Member

shilman commented Jun 11, 2020

Yay!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-beta.24 containing PR #11086 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

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

No branches or pull requests

3 participants