简体   繁体   English

Babel在使用Create-React-App时不翻译Map()

[英]Babel does not translate Map() when using Create-React-App

I have a React App using Create-React-App. 我有一个使用Create-React-App的React App。 I've used the Map() datastructure included in ES6 in my app. 我在我的应用程序中使用了ES6中包含的Map()结构。 However, in IE11 it does not work. 但是,在IE11中它不起作用。 Shouldn't Babel (under the hood of Create-React-App - I did not eject) take care of this? Babel(在Create-React-App的掩护下-我没有弹出)不应该照顾这个吗?

If not, is there there any solution for that? 如果没有,那有什么解决办法吗?

As others already mentioned, you are going to need a polyfill to add the functionality when it's not natively supported by the browser in question. 正如其他人已经提到的那样,当相关浏览器本身不支持该功能时,您将需要使用polyfill来添加该功能。 Since you're already using Babel, the easiest way to do this is by using a Babel polyfill. 由于您已经在使用Babel,因此最简单的方法是使用Babel polyfill。

If you don't want to add another dependency, you can use the Map polyfill found here . 如果您不想添加其他依赖项,则可以使用在此处找到的Map polyfill。

No. 没有。

Use babel-polyfill for cross-browser babel support: babel-polyfill用于跨浏览器的babel支持:

npm install --save babel-polyfill

If you're using webpack/browserify then here's how you should incorporate the polyfill: 如果您使用的是webpack / browserify,则应采用以下方式合并polyfill:

module.exports = {
  entry: ["babel-polyfill", "./app/js"]
};

If you're still unclear, read the documentation here . 如果您仍然不清楚,请阅读此处的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 babel & web pack with react without create-react-app - Using babel & web pack with react without create-react-app 为什么 2020 年 create-react-app 仍然包含 babel - why does create-react-app still include babel in 2020 带有babel和webpack的npm create-react-app无法正常工作 - npm create-react-app with babel and webpack does not work 当使用express,create-react-app和babel-node时,我得到“React not defined” - I get “React not defined” when using express, create-react-app and babel-node 未弹出时,create-react-app应用程序会将babel配置存储在哪里? - Where does create-react-app application store it's babel configuration when not ejected? 使用 react-map-gl 和 create-react-app 时 Map 未显示 - Map not showing up when using react-map-gl and create-react-app 在create-react-app中使用react-map-gl时出错 - Error using react-map-gl in create-react-app 在使用“ create-react-app”实用程序创建的React应用程序中无法解决Babel依赖性 - Babel dependency not resolved in react app created using “create-react-app” utility 没有babel或任何构建工具的create-react-app工具如何工作? - How does create-react-app tool work without babel or any build tool? 将模块导入新的 create-react-app 项目时,构建时出现 Babel/JSX Transpiler 错误 - Babel/JSX Transpiler error on build when importing a module into new create-react-app project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM