javascript 未捕获的 ReferenceError:未定义 Promise

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23189298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:30:22  来源:igfitidea点击:

Uncaught ReferenceError: Promise is not defined

javascriptgoogle-chromepromisegoogle-chrome-app

提问by Fabis

A Chrome App I've made works perfectly fine for me, but another user gets an error Uncaught ReferenceError: Promise is not definedwhen starting it up. For some reason it doesn't understand what a Promise is. The code works perfectly fine on my end and I've never gotten that error before, but the user gets it every time. What could be the issue here?

我制作的 Chrome 应用程序对我来说非常好,但另一个用户Uncaught ReferenceError: Promise is not defined在启动时遇到错误。出于某种原因,它不明白 Promise 是什么。代码在我这边工作得很好,我以前从来没有遇到过这个错误,但用户每次都会得到它。这里可能有什么问题?

采纳答案by Fabis

The user updated Chrome to the latest version and that apparently fixed it. I don't know how, since his version was from December 2013 and surely Promises worked back then. I don't know. It definitely isn't a problem with the code since I'm running the same exact version the user is running and I've never encountered that error.

用户将 Chrome 更新到最新版本,这显然修复了它。我不知道如何,因为他的版本是从 2013 年 12 月开始的,而且当时 Promises 肯定有效。我不知道。代码绝对不是问题,因为我运行的版本与用户运行的版本完全相同,而且我从未遇到过该错误。

But yeah - apparently fixed.

但是是的 - 显然是固定的。

EDIT: Apparently Promises only work since Chrome 32, so yeah that's why the error.

编辑:显然 Promises 只从 Chrome 32 开始工作,所以是的,这就是错误的原因。

回答by Florian Ledermann

To support IE and older versions of other browsers, you should consider loading a polyfill for the Promise object.

为了支持 IE 和其他浏览器的旧版本,你应该考虑为 Promise 对象加载一个 polyfill。

One implementation you can use out of the box with a <script>tag is available here.

您可以在此处使用带有<script>标签的开箱即用的一种实现。

回答by hassan ketabi

Primise in Old Browsers

旧浏览器中的 Primise

?Android 4.x browser Promise?

?Android 4.x 浏览器承诺

I had similar problem ?in Android 4.X browsers. I solved it by using es6-promise in webpack config: ? ?Promise: 'es6-promise' ?

我有类似的问题?在 Android 4.X 浏览器中。我通过在 webpack 配置中使用 es6-promise 解决了这个问题:?承诺:'es6-promise' ?

?plugins: [
    ?    //tells webpack where to store data about your bundles.
    ?    new BundleTracker({filename: './webpack-stats.json'}),        ?
    ?    //makes jQuery available in every module
    ?    new webpack.ProvidePlugin({
    ?        $: 'jquery',        ?
    ?        jQuery: 'jquery',
    ?        'window.jQuery': 'jquery',
    ?        Promise: 'es6-promise'
    ?    }),
?    // Configure path for served CSS files ("desktop_css" will be served as /dist/desktop_css.css)    ?
?    new ExtractTextPlugin('[name].css'),    ?
?],


Can I use Promise: ?http://caniuse.com/#feat=promises

我可以使用 Promise: 吗?http://caniuse.com/#feat=promises



some related links:

一些相关链接:

??axios IE promise doesn't work

?? axios IE 承诺不起作用

https://github.com/axios/axios/issues/188

https://github.com/axios/axios/issues/188

https://github.com/webpack/webpack/issues/4254

https://github.com/webpack/webpack/issues/4254