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

Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". #8

Open
alexmercier25 opened this issue Jun 4, 2021 · 2 comments
Open

Comments

@alexmercier25
Copy link

Hi. When I try to build my files, it gives me this error.

I think that's because Babel 6.23.0 is used by drupal-js-build. I was wondering if you can update the version?

Thanks

@tanc
Copy link

tanc commented Jan 19, 2022

Also seeing this problem

@tanc
Copy link

tanc commented Jan 19, 2022

A bit more info and a solution: In my case I have a module for Gutenberg which has scripts for building a Gutenberg block in JavaScript. The requirements for that are Babel@^7.0 but I also need to build Drupal JS in the same module. The error gets thrown due to .babelrc specifying presets. If I comment out .babelrc then no error is thrown.

In babelrc it is possible to restrict presets and plugins to specific environments. In mine I've set the needed config to only apply in the NODE_ENV=babel7 environment:

{
  "env": {
    "babel7": {
      "presets": ["@babel/preset-env", "@babel/preset-react"],
      "plugins": [["@babel/plugin-proposal-class-properties"]]
    }
  }
}

This way I can run my build script like this (from package.json):

"build": "NODE_ENV=babel7 wp-scripts build",

and my drupal-js-build from the command line like this:

npx drupal-js-build

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

No branches or pull requests

2 participants