


webpack+babel+transform-runtime, IE prompts Promise undefined solution
Knowledge requirements
Basic knowledge of babel
(recommend Ruan Yifeng’s babel introductory tutorial)Fully understand The role of
babel-plugin-transform-runtime
andbabel-runtime
(recommended github project homepage)webpack2
Basic usagewebpack2
babel-loader
function,import
asynchronous loading
Problem Description
webpack
+babel-loader
+transform-runtime
Normally speaking, it should be possible without native support# It runs normally under Promise
browsers (such as IE
), but actually under IE11
, an Promise
undefined error is still prompted. I searched around on the Internet, but couldn't find anything that hit the mark, so I just analyzed it myself.
Analysis
First confirm whether the transform-runtime
of babel
is effective, in your own Write the sample code of
var promise = new Promise(resolve, reject) in js
code, and find that Promise
has been replaced. So the key to the question is what is beyond babel
's control?
What I am thinking of is node_modules
versus webpack
the code generated by itself.
Before using babel
to convert ES6
, the third-party packages referenced through node_modules
can be used normally, so they can be excluded.
So webpack
, search webpack promise not defined
in GOOGLE
, and I really found the reason, as shown in the figure below:
When using asynchronous loading of webpack
, webpack
requires native support for Promise
, which happens to be useful for our code. At this point, the reason has been found: the
related code generated by webpack
exceeds the transform-runtime## of
babel #'s control scope, only exporting the global
Promise can solve this problem.
- Introduction
babel-polyfill
Export global
Promise, this method is not good; not only
Promiseis exported and also throws out a large number of other global objects, which may cause conflict risks, and the file size is relatively large.
window.Promise = Promise at the beginning of the
js file, sample code :
import 'jquery' import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap' // 将Promise抛出为全局对象 window.Promise = Promise 。。。
babel checks the
Promise of
js,
transform-runtime will
Promise Convert it and then throw it as a global object to achieve the same effect as
babel-polyfill.
The above is the detailed content of webpack+babel+transform-runtime, IE prompts Promise undefined solution. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In daily life, we often encounter problems between promises and fulfillment. Whether in a personal relationship or a business transaction, delivering on promises is key to building trust. However, the pros and cons of commitment are often controversial. This article will explore the pros and cons of commitments and give some advice on how to keep your word. The promised benefits are obvious. First, commitment builds trust. When a person keeps his word, he makes others believe that he is a trustworthy person. Trust is the bond established between people, which can make people more

Vue is a popular front-end framework, and you often encounter various errors and problems when developing applications. Among them, Uncaught(inpromise)TypeError is a common error type. In this article, we will discuss its causes and solutions. What is Uncaught(inpromise)TypeError? Uncaught(inpromise)TypeError error usually appears in

Form validation is a very important link in web application development. It can check the validity of the data before submitting the form data to avoid security vulnerabilities and data errors in the application. Form validation for web applications can be easily implemented using Golang. This article will introduce how to use Golang to implement form validation for web applications. 1. Basic elements of form validation Before introducing how to implement form validation, we need to know what the basic elements of form validation are. Form elements: form elements are

Web standards are a set of specifications and guidelines developed by W3C and other related organizations. It includes standardization of HTML, CSS, JavaScript, DOM, Web accessibility and performance optimization. By following these standards, the compatibility of pages can be improved. , accessibility, maintainability and performance. The goal of web standards is to enable web content to be displayed and interacted consistently on different platforms, browsers and devices, providing better user experience and development efficiency.

Cockpit is a web-based graphical interface for Linux servers. It is mainly intended to make managing Linux servers easier for new/expert users. In this article, we will discuss Cockpit access modes and how to switch administrative access to Cockpit from CockpitWebUI. Content Topics: Cockpit Entry Modes Finding the Current Cockpit Access Mode Enable Administrative Access for Cockpit from CockpitWebUI Disabling Administrative Access for Cockpit from CockpitWebUI Conclusion Cockpit Entry Modes The cockpit has two access modes: Restricted Access: This is the default for the cockpit access mode. In this access mode you cannot access the web user from the cockpit

Detailed explanation of Promise.resolve() requires specific code examples. Promise is a mechanism in JavaScript for handling asynchronous operations. In actual development, it is often necessary to handle some asynchronous tasks that need to be executed in sequence, and the Promise.resolve() method is used to return a Promise object that has been fulfilled. Promise.resolve() is a static method of the Promise class, which accepts a

The web is a global wide area network, also known as the World Wide Web, which is an application form of the Internet. The Web is an information system based on hypertext and hypermedia, which allows users to browse and obtain information by jumping between different web pages through hyperlinks. The basis of the Web is the Internet, which uses unified and standardized protocols and languages to enable data exchange and information sharing between different computers.

PHP belongs to the backend in web development. PHP is a server-side scripting language, mainly used to process server-side logic and generate dynamic web content. Compared with front-end technology, PHP is more used for back-end operations such as interacting with databases, processing user requests, and generating page content. Next, specific code examples will be used to illustrate the application of PHP in back-end development. First, let's look at a simple PHP code example for connecting to a database and querying data:
