dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

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

Open nicolo-ribaudo opened 2 years ago

nicolo-ribaudo commented 2 years ago

What happens?

(cross-posting from https://github.com/babel/babel/issues/14568#issuecomment-1133589525)

At line 445 of https://unpkg.com/browse/dva-core@2.0.4/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/dva-core@2.0.4/dist/index.esm.js that it uses the local _regeneratorRuntime variable, imported at line 17.

Mini Showcase Repository(REQUIRED)

https://github.com/babel/babel/issues/14568#issuecomment-1133184851=

Context

nicolo-ribaudo commented 2 years ago

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 :sweat_smile:


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.