首页 > 解决方案 > Webpack Encore 与 Babel

问题描述

我在浏览器控制台中收到以下错误:

未捕获的 ReferenceError:未定义 regeneratorRuntime

我在这里找到了一个问题和答案,说要安装 Babel 以使其正常工作,所以我开始这样做。现在就上下文而言,我之前从未使用过 Webpack Encore 或 Babel。我从来不需要。我在我的 Webpack Encore 文件中添加了以下几行,但又遇到了另一个错误。

Encore.configureBabel(() => {}, {
    useBuiltIns: 'usage',
})
[ encore ] Module build failed (from ./node_modules/babel-loader/lib/index.js):
RangeError: [BABEL] \resources\js\app.ts: Invalid Option: The version passed to `corejs` is invalid. Currently, only core-js@2 and core-js@3 are supported. (While processing: "\\node_modules\\@babel\\preset-env\\lib\\index.js")
    at normalizeCoreJSOption (\node_modules\@babel\preset-env\lib\normalize-options.js:114:11)
    at normalizeOptions (\node_modules\@babel\preset-env\lib\normalize-options.js:126:18)
    at \node_modules\@babel\preset-env\lib\index.js:271:37
    at \node_modules\@babel\helper-plugin-utils\lib\index.js:22:12
    at async (\node_modules\@babel\core\lib\gensync-utils\async.js:43:33)
    at async (\node_modules\gensync\index.js:186:15)
    at \node_modules\gensync\index.js:216:13
    at Generator.next (<anonymous>)
    at \node_modules\@babel\core\lib\config\full.js:217:21
    at Generator.next (<anonymous>)

有了这个错误,我在corejs: '3.0.0',下面添加useBuiltIns了更多错误。我发现的另一个问题表明 corejs 只会useBuiltIns: 'usage'过时。

对于 async/await 功能来说,这一切都变得有点过分了。在我的浏览器中运行的功能。

标签: javascriptnode.jsbabeljswebpack-encore

解决方案


推荐阅读