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

Fix test error: "babelHelpers is not defined" #8

Merged
merged 1 commit into from
Sep 23, 2020

Conversation

marilyn79218
Copy link
Owner

@marilyn79218 marilyn79218 commented Sep 23, 2020

  • (Initial) command yarn start works well on master, but yarn test failed for error ReferenceError: babelHelpers is not defined.

Regarding to this thread:

This is because you're using '@babel/plugin-external-helpers', in your plugin list. If you do that, it is up to you to load the helpers. '@babel/plugin-transform-runtime', already loads an alternative approach for helpers, so I would just remove the external helpers plugin.

First step is install new package @babel/plugin-transform-runtime but it will lead to another failure Error: Cannot find module '@babel/core' where it tries to find the latest babel@7 however we are using babel@6.
Hence, we are installing a legacy version of that package [babel-plugin-transform-runtime] to achieve the original purpose.

  • The command yarn test works well now!
  • But yarn start failed for error:

Error: Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the runtimeHelpers: true option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information

Then we found this, where it says

Alternatively, if you know what you're doing, you can use the transform-runtime plugin. If you do this, use runtimeHelpers: true:

rollup.rollup({
  ...,
  plugins: [
    babel({ runtimeHelpers: true })
  ]
}).then(...)

That's it! Then everything works well now.

@marilyn79218 marilyn79218 merged commit cca31c6 into master Sep 23, 2020
@marilyn79218 marilyn79218 deleted the fix/fix-test-error branch September 23, 2020 18:33
@marilyn79218 marilyn79218 mentioned this pull request Sep 23, 2020
@marilyn79218
Copy link
Owner Author

marilyn79218 commented Sep 23, 2020

Also, we are not upgrading babel@6 to babel@7 because there're too many existing packages are legacy itself and they depend on legacy babel@6 as well.

But still, it is very useful to have basic knowledge about babel when you're updating it. Eg, if you're upgrading babel-preset-env to @babel/preset-env, then you will need to update .babelrc accordingly (see thread)

Just like env is now @babel/env, react should be @babel/react and you'll need to install @babel/preset-react.

{
  "presets": [
    [
      "env", // should update to `@babel/env`
      {
        "modules": false
      }
    ],
    "react" // should update to `@babel/react`
  ],
  "env": {
    "test": {
      "presets": [
        [
          "env" // should update to `@babel/env`
        ],
        "react" // should update to `@babel/react`
      ]
    }
  },

@marilyn79218
Copy link
Owner Author

marilyn79218 commented Sep 23, 2020

Also, if you updated babel-jest@22 to babel-jest@26 in our current project, you will also need to update jest@22 to jest@26 accordingly, see this thread for detail

your reproduction uses jest@23 with babel-jest@24 - that's not supported. Upgrading to jest@24 makes your test pass.

@marilyn79218
Copy link
Owner Author

marilyn79218 commented Sep 23, 2020

For some experimental upgrades, see this PR.

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

Successfully merging this pull request may close these issues.

1 participant