简体   繁体   English

Create-React-App 在 IE11 上显示空白屏幕。 错误:SCRIPT5009:'WebSocket' 未定义和 SCRIPT5009:'Promise' 未定义

[英]Create-React-App displaying blank screen on IE11. ERRORS: SCRIPT5009: 'WebSocket' is undefined and SCRIPT5009: 'Promise' is undefined

CRA works fine on every other browser but displaying blank screen on IE. CRA 在其他所有浏览器上都可以正常工作,但在 IE 上显示空白屏幕。 I have tried installing react-app-polyfill 2.0 and 1.0.6, putting import "react-app-polyfill/ie11" import "react-app-polyfill/stable" at the top of src/index.js file.我尝试安装 react-app-polyfill 2.0 和 1.0.6,将 import "react-app-polyfill/ie11" import "react-app-polyfill/stable" 放在 src/index.js 文件的顶部。 As well as putting "ie 11" in the browserList for dev and prod env.以及将“ie 11”放入 dev 和 prod env 的 browserList 中。 I also removed the.cache file in node_modules and still same error pops up.我还删除了 node_modules 中的 .cache 文件,但仍然弹出相同的错误。 Here is my code:这是我的代码:

package.json file dependencies package.json 文件依赖

paackage.json file browserList包.json文件浏览器列表

Polyfill imports Polyfill 进口

Here are the error messages I am getting:以下是我收到的错误消息:

Whole error整个错误

'WebSocket'is undefined points to this 'WebSocket' 未定义指向此

'Promise' is undefined error points to this 'Promise' 是未定义的错误点

As we can see that you had already added the react-app-polyfill and added the "ie 11" in the browser list.我们可以看到您已经添加了react-app-polyfill并在浏览器列表中添加了"ie 11"

I suggest you keep those settings and refer to the steps below.我建议您保留这些设置并参考以下步骤。

If this is a newly created app and not working with IE 11 then I suggest you install core-JS using the command npm install core-js and add import 'core-js/stable' on the first line in the index.js file.如果这是一个新创建的应用程序并且不能使用 IE 11,那么我建议您使用命令npm install core-jsindex.js文件的第一行添加import 'core-js/stable'

The starting of the index.js file should look like below. index.js文件的开头应如下所示。

import 'core-js/stable';
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import React from 'react';
import ReactDOM from 'react-dom';

After that delete the .cache folder under node_modules and again try to run the project.之后删除.cache下的node_modules文件夹,然后再次尝试运行该项目。 It may help you to run it in IE 11.它可以帮助您在 IE 11 中运行它。

在此处输入图像描述

If your React app was working with IE 11 and you got this issue after adding some code then I suggest you try to provide detailed information about it.如果您的 React 应用程序正在使用 IE 11,并且您在添加一些代码后遇到此问题,那么我建议您尝试提供有关它的详细信息。 It can help us to understand the issue properly.它可以帮助我们正确理解问题。

Thanks for your understanding.感谢您的理解。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM