gpt4 book ai didi

javascript - Vue 3 CLI - 如何为 Object.entries 添加 babel polyfill

转载 作者:数据小太阳 更新时间:2023-10-29 05:37:17 31 4
gpt4 key购买 nike

我有一个依赖项 (vue2-google-maps),它导致我的 Vue 应用程序在旧版浏览器中出现问题,并引发 Object.entries 错误。

阅读Vue CLI Docs on polyfills ,我看到它提到尝试在 babel.config.js 中加载 polyfill。

我的babel.config.js:

module.exports = {
presets: [
['@vue/app', {
polyfills: [
'es6.object'
]
}]
]
}

抛出错误:

Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: [BABEL] /PROJECT_DIR/src/main.js: Cannot read property 'android' of undefined (While processing: "/PROJECT_DIR/node_modules/@vue/babel-preset-app/index.js")
at targetEnvironments.filter.environment (/PROJECT_DIR/node_modules/@babel/preset-env/lib/index.js:75:16)
at Array.filter (<anonymous>)
at isPluginRequired (/PROJECT_DIR/node_modules/@babel/preset-env/lib/index.js:74:56)
at includes.filter.item (/PROJECT_DIR/node_modules/@vue/babel-preset-app/index.js:23:12)
at Array.filter (<anonymous>)
at getPolyfills (/PROJECT_DIR/node_modules/@vue/babel-preset-app/index.js:22:19)
at module.exports (/PROJECT_DIR/node_modules/@vue/babel-preset-app/index.js:94:17)
at loadDescriptor (/PROJECT_DIR/node_modules/@babel/core/lib/config/full.js:163:14)
at cachedFunction (/PROJECT_DIR/node_modules/@babel/core/lib/config/caching.js:42:19)
at loadPresetDescriptor (/PROJECT_DIR/node_modules/@babel/core/lib/config/full.js:233:63)
at config.presets.map.descriptor (/PROJECT_DIR/node_modules/@babel/core/lib/config/full.js:68:19)
at Array.map (<anonymous>)
at recurseDescriptors (/PROJECT_DIR/node_modules/@babel/core/lib/config/full.js:66:38)
at loadFullConfig (/PROJECT_DIR/node_modules/@babel/core/lib/config/full.js:106:6)
at process.nextTick (/PROJECT_DIR/node_modules/@babel/core/lib/transform.js:28:33)
at process._tickCallback (internal/process/next_tick.js:112:11)

@ multi (webpack)-dev-server/client?http://192.168.1.201:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

我做错了什么?我使用 Vue CLI 3.0.3

创建了项目

最佳答案

您需要将 es6.object 更改为 es7.object.entries 以使 Object.entries 在旧版浏览器上工作。

所以你的 /babel.config.js 应该如下所示:

module.exports = {
presets: [
[
"@vue/app",
{
polyfills: ["es7.object.entries"]
}
]
]
};

我在这里找到了 polyfills 名称:built-in-features.js#L153

关于javascript - Vue 3 CLI - 如何为 Object.entries 添加 babel polyfill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52475423/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com