我正在开发一个基于浏览器的项目,需要兼容 IE11(叹气)。Webpack 令人窒息async/await。这是我的控制台的输出:
Based on your code and targets, added regenerator-runtime.
...
Module not found: Error: Can't resolve 'regenerator-runtime/runtime'
Run Code Online (Sandbox Code Playgroud)
我看过很多与我类似的问题,但没有运气。许多人建议使用@babel/polyfill我避免使用的方法,因为它已被弃用。
是什么导致了这个问题?我希望它可以通过手动导入来修复regenerator-runtime/runtime,但它的主要卖点之一似乎babel-env是不必手动导入polyfills,所以我认为我错过了一个步骤。谢谢你!
这是我正在尝试运行的内容,它将被导入到另一个文件中:
class Fetcher {
constructor() {
this.form = document.querySelector('form');
this.form.addEventListener('submit', this.onSubmit.bind(this));
}
async onSubmit(event) {
event.preventDefault();
const apiResponse = await fetch(`${WP_url}/api`);
const apiJson = await apiResponse.json();
console.log(apiJson);
}
}
export default Fetcher;
Run Code Online (Sandbox Code Playgroud)
webpack.config.js:
const path = require('path');
function pathTo(filepath) {
return path.join(__dirname, filepath);
}
module.exports = function(env, …Run Code Online (Sandbox Code Playgroud)