未捕获的 ReferenceError 与 redux-saga

Uncaught ReferenceError with redux-saga

我正在尝试使用 redux-saga 模块。

但是我有以下错误。

Uncaught ReferenceError: regeneratorRuntime is not defined
    at eval (saga.js:5)
    at Object../js/sagas/saga.js (saga.js:393)
    at __webpack_require__ (saga.js:20)
    at eval (configureStore.js:8)
    at Object../js/stores/configureStore.js 

saga.js很简单。

export function* helloSaga(){
    console.log('Hello Sagas!');
}

并且我已经安装了以下模块。

npm install @babel/polyfill --save

上面发生了什么?

检查你的 babel 配置。

对于@babel/preset-env 检查 excludeuseBuiltIns 选项: https://babeljs.io/docs/en/babel-preset-env#exclude

对于@babel/preset-transform-runtime检查regenerator选项:
https://babeljs.io/docs/en/babel-plugin-transform-runtime#regenerator

此外,@babel/polyfill 已被弃用,有利于在 babel 7.4 中直接使用 core-js 和 regenerator-runtime/runtime:
https://babeljs.io/blog/2019/03/19/7.4.0#migration-from-core-js-2
https://babeljs.io/docs/en/babel-polyfill

最后,尝试在您的 babel-loader 中显式设置 .babelrc 的路径。我有一个理论,babel 使用不同的 .babelrc 名称默认值来解决它的一些任务。
https://babeljs.io/docs/en/options#configfile or
https://babeljs.io/docs/en/options#extends

我终于开始使用 @babel/polyfill,即使它是重复的。

npm install @babel/polyfill --save 
import '@babel/polyfill';

export function* helloSaga(){
    console.log('Hello Sagas!');
}

错误不出来。成功了。