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

dva-core CJS build relies on a regeneratorRuntime global, but it isn't defined #2493

Open
nicolo-ribaudo opened this issue May 21, 2022 · 1 comment

Comments

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented May 21, 2022

What happens?

(cross-posting from babel/babel#14568 (comment))

At line 445 of https://unpkg.com/browse/[email protected]/dist/index.js, dva-core uses the regeneratorRuntime global (which is injected by Babel). However, that global variable is not defined anywhere.

There are three possible fixes:

  1. Add require("regenerator-runtime"), which defines the global regeneratorRuntime variable so that it can be used
  2. Use @babel/plugin-transform-runtime to inject the necessary @babel/runtime imports
  3. Update @babel/core and @babel/plugin-transform-regenerator to ^7.18.0, so that the compiled output doesn't rely on a regeneratorRuntime global anymore.

Surprisingly, the ESM build already follows the 2nd solution and thus isn't affected by this bug. You can see at line 316 of https://unpkg.com/browse/[email protected]/dist/index.esm.js that it uses the local _regeneratorRuntime variable, imported at line 17.

Mini Showcase Repository(REQUIRED)

babel/babel#14568 (comment)

Context

  • Dva Version: 2.0.4
  • Node Version: doesn't matter
  • Platform: doesn't matter
@nicolo-ribaudo
Copy link
Author

nicolo-ribaudo commented May 21, 2022

I tried understanding your build process and this might be a bug with https://github.com/umijs/father, but I cannot find where it's configured for this repository 😅


EDIT: Yes, this is a bug with father-build: it explicitly ignores the runtimeHelpers option (that you correctly configured in packages/dva-core/.fatherrc.js) when compiling CJS: https://github.com/umijs/father/blob/2be23ea5198d00b98ad67e92b6b92583a91353d7/packages/father-build/src/getRollupConfig.ts#L79

You could either choose solution (1) or (3), or we could repost this bug in 'father-build` so that (2) works for CJS as it does for ESM.

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

1 participant