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-jest is incompatible with plugins made for Babel 7 #4055

Closed
bradchristensen opened this issue Jul 18, 2017 · 1 comment · Fixed by #4162
Closed

babel-jest is incompatible with plugins made for Babel 7 #4055

bradchristensen opened this issue Jul 18, 2017 · 1 comment · Fixed by #4162

Comments

@bradchristensen
Copy link
Contributor

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When using babel-jest in a project using Babel 7, babel-jest still attempts to transform code using babel-core@6 (because it is specified as a dependency rather than a peerDependency), which is not necessarily compatible with the plugins/presets that the user will have included in the project.

For example, I have a project using Babel 7 and the babel-plugin-transform-object-rest-spread Babel plugin. If I have version 7.0.0-alpha.15 installed, babel-jest behaves as if the plugin is not referenced at all, throwing the error:

    function ProfileLabel({ className, ...props }) {
                                       ^^^

    SyntaxError: Unexpected token ...

However, if the version of babel-core installed as a dependency of babel-jest is changed to version 7.0.0-alpha.15, the plugin is used correctly and the code is transpiled as expected.

What is the expected behavior?

It seems to me that the obvious solution to this would be to change babel-core to be a peerDependency instead of a dependency, since any projects that rely on babel-jest presumably have to have babel-core installed anyway. Even though this would be a breaking change it would maintain backwards compatibility with Babel 6. I have tested and confirmed on my machine that modifying the package.json as follows fixes the issue.

{
  ...
  "dependencies": {
    "babel-plugin-istanbul": "^4.0.0",
    "babel-preset-jest": "^20.0.3"
  },
  "devDependencies": {
    "babel-core": "^7.0.0-alpha.15"
  },
  "peerDependencies": {
    "babel-core": "^6.0.0 || ^7.0.0-alpha || ^7.0.0"
  }
}
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant