该错误是由于在Babel 7中,不再默认包含regenerator-runtime库的原因导致的。要解决这个问题,你需要手动安装和引入regenerator-runtime库。
下面是一个解决此问题的代码示例:
npm install --save regenerator-runtime
import 'regenerator-runtime/runtime';
或者,如果你使用的是CommonJS模块化语法:
require('regenerator-runtime/runtime');
例如:
async function myAsyncFunction() {
await someAsyncTask();
console.log('Async task completed.');
}
myAsyncFunction();
这样就解决了Babel 7中出现"ReferenceError: regeneratorRuntime is not defined"的问题。