`dva-core` CJS build relies on a `regeneratorRuntime` global, but it isn't defined
nicolo-ribaudo opened this issue · 1 comments
What happens?
(cross-posting from babel/babel#14568 (comment))
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:
- Add
require("regenerator-runtime")
, which defines the globalregeneratorRuntime
variable so that it can be used - Use
@babel/plugin-transform-runtime
to inject the necessary@babel/runtime
imports - Update
@babel/core
and@babel/plugin-transform-regenerator
to ^7.18.0, so that the compiled output doesn't rely on aregeneratorRuntime
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)
Context
- Dva Version: 2.0.4
- Node Version: doesn't matter
- Platform: doesn't matter
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.