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

[Bug] CRA preset does not support ES2020 dependencies #212

Open
ph-fritsche opened this issue Sep 6, 2021 · 2 comments
Open

[Bug] CRA preset does not support ES2020 dependencies #212

ph-fritsche opened this issue Sep 6, 2021 · 2 comments
Labels
bug Something isn't working create-react-app

Comments

@ph-fritsche
Copy link

Describe the bug

Storybook + CRA preset fails due to ModuleParseError for projects containing dependencies in ES2020.

Steps to reproduce the behavior

  1. Import a dependency with ES2020 syntax.
  2. Start storybook.

See https://github.com/ph-fritsche/repro-storybook-es2020

Expected behavior

Accept imports with ES2020 like CRA does.

Environment

  • OS: Debian
  • Node.js version: 16.0.0
  • NPM version: 7.10.0
@ph-fritsche ph-fritsche added the bug Something isn't working label Sep 6, 2021
@ghost
Copy link

ghost commented Jul 14, 2023

@ph-fritsche Were you able to work around this?

@ghost
Copy link

ghost commented Jul 14, 2023

I was able to solve this with the following workaround:

  webpackFinal: async (config) => {
    // preset-create-react-app adds an include for the catch-all JS rule and
    // we need to remove it to allow ES2020 syntax in dependencies
    config.module.rules = config.module.rules.map((rule) => {
      if (!rule.oneOf) {
        return rule;
      }

      return {
        oneOf: rule.oneOf.map((oneOfRule) => {
          if (
            Array.isArray(oneOfRule.include) &&
            oneOfRule.include.length === 1 &&
            oneOfRule.include[0] === path.resolve(__dirname)
          ) {
            delete oneOfRule.include;
          }

          return oneOfRule;
        }),
      };
    });

    return config;
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working create-react-app
Projects
None yet
Development

No branches or pull requests

2 participants