GithubHelp home page GithubHelp logo

react-ie8's Introduction

中文 README

Make your React app work in IE8

It's really a dispiriting news that Starting with React v15, we're discontinuing React DOM's support for IE 8. There are still more than 18% people who are using IE8 in China.

Anyway, react-ie8 will continuously provide a series of Examples for people who are facing the same compatible problems, as well as collecting issues.

Have fun with react-ie8 Examples, and feel free to Open an issue.

How to

First you shouldn't use React v15 or higher version anymore. Just use React v0.14 which still support IE8.

If you need docs for React v0.14, go to http://react-ie8.xcatliu.com

Using CommonJS

I highly recommend to use CommonJS style to include required packages.

First install these packages:

npm install --save es5-shim console-polyfill

Then insert the code into the beginning of your entry file:

require('es5-shim');
require('es5-shim/es5-sham');
require('console-polyfill');

See React IE8 Hello World Example for a real example.

React Static Boilerplate

React Static Boilerplate A React static boilerplate that supports IE8,To view Demo

Other Problems

Some problems are actually not the problem of React, but I also list them below:

Error Message Reason Solution Related Issue Example
Expected identifier Reserved words such as default are used in your code or in third party packages Use es3ify or es3ify-loader to transform your code #1 Fetch IE8
Exception thrown and not caught Babel transforms your export * from 'xxx' to Object.defineProperty which doesn't support accessor property in IE8 Insert require('es5-shim') require('es5-shim/es5-sham') in the top of your entry file, and DONOT use export * from 'xxx' in your code #2 #32 Hello World
Object expected Perhaps you are using fetch without polyfilled Use es6-promise and fetch-ie8 to polyfill fetch #4 Fetch IE8
'Promise' is undefined Promise need to be polyfilled in IE8 Use es6-promise to polyfill Promise #5 Fetch IE8
Object doesn't support this property or method Perhaps you are using Object.assign Use core-js to polyfill #7 Object Assign
'JSON' is undefined Need to use IE8 Standards Mode Add <!DOCTYPE html> and <meta http-equiv="X-UA-Compatible" content="IE=EDGE"/> #8 Hello World

If you have other problems, please Open an issue.

Troubleshooting

Troubleshooting in issues

Reference

使你的 React 应用兼容 IE8

一个令人失望的消息:从 React v15 开始,React DOM 将不会再支持 IE8 了。而**还有超过 18% 的人在使用 IE8

无论如何,react-ie8 仍会提供一系列的示例,还会收集 issues,以便于给遇到兼容性问题的人一个参考。

快去查看 react-ie8 示例吧,也欢迎提交 issue

如何兼容 IE8

首先,你不应该使用 React v15 或更高版本。使用仍然支持 IE8 的 React v0.14 即可。

如果你需要查看 React v0.14 的文档,请访问:http://react-ie8.xcatliu.com

使用 CommonJS

强烈推荐使用 CommonJS 风格来引入需要的模块。

首先安装这些模块:

npm install --save es5-shim console-polyfill

然后把以下代码插入到入口文件最前面

require('es5-shim');
require('es5-shim/es5-sham');
require('console-polyfill');

参考一个真实的例子:React IE8 Hello World Example

使用 React Static Boilerplate

React Static Boilerplate 一个创建好的支持 IE8 的 React 静态模板,可以查看演示

其他问题

一些问题其实并不是 React 的问题,不过我也把他们列出来了:

错误信息 原因 解决方案 相关 Issue 示例
Expected identifier 代码中或者第三方模块中使用了保留字,比如 default 使用 es3ify 或者 es3ify-loader #1 Fetch IE8
Exception thrown and not caught babel 把 export * from 'xxx' 编译成了 Object.defineProperty,而 IE8 中不支持 accessor property require('es5-shim') require('es5-shim/es5-sham') 插入到入口文件的最上方,并且在代码中不要使用 export * from 'xxx' #2 #32 Hello World
Object expected 可能你使用了 fetch es6-promisefetch-ie8 polyfill #4 Fetch IE8
'Promise' is undefined Promise 需要 polyfill es6-promise polyfill #5 Fetch IE8
Object doesn't support this property or method 可能你使用了 Object.assign core-js polyfill #7 Object Assign
'JSON' is undefined 需要使用 IE8 Standards Mode 添加 <!DOCTYPE html><meta http-equiv="X-UA-Compatible" content="IE=EDGE"/> #8 Hello World

如果你遇到了其他问题,可以提交一个 issue

Troubleshooting

Troubleshooting in issues

参考

react-ie8's People

Contributors

dzcpy avatar xcatliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-ie8's Issues

有关Object.defineProperties的问题

怎么才能让babel6 的import不生成Object.defineProperties的代码?

我这边已经干掉了好些依赖 不想使用es5-shim等polyfill 有办法么?

how to run in IE8

how to fix IE8(请问如何兼容IE8),when I clone this code and run,but it's still can't run in IE8(下载后仍然无法运行)

Production Build

how do i create prod build. Currently the compiled file is quite large.

在IE8下无法运行

React Static Boilerplate 的在线演示,用IE8打开直接报错 “HTTP ERROR -2146697208”

Make your React app work in IE8 with one liner code

As I know, It's very painful to solve compatibility Issues in IE8.
So I'm considering to write a package to help people who are facing such problems.

With just one liner code:

require('react-ie8')(options);

Or insert umd js file into head?

<script src=".../react-ie8.js"></script>
<script>window.reactIE8(options)</script>

Babel transform "export xx from 'xxx' " to Object.defineProperty

"Babel transforms your import to Object.defineProperty which doesn't exist in IE8。"
It should be 'export' ,not 'import' . IE8 has Object.defineProperty Object.defineProperty.
now Babel fixed the transform, but has another problem: Babel transform "export xx from 'xxx' " to Object.defineProperty, like:
"
Object.defineProperty(exports, 'LOCATION_CHANGE', {
enumerable: true,
get: function get() {
return _reducer.LOCATION_CHANGE;
}
});
"
the accessor property not support in ie8.
so cannot use react-router-redux because it use "export xx from 'xxx' ";

建议fish样式进行隔离

iconfont的unicode没有‘fish化’,如果antd和fish同时使用 有时候会出问题,建议加前缀什么的 隔离一下

IE8 Object.defineproperty 问题

目前错误信息,了解到是某个地方使用了Object.defineproperty,但是我已经重构了代码应该没有这种问题,极有可能是依赖的第三方库的问题,我已经手动改了报错的库例如react-router-redux,并且已经把明确不支持IE8的库要么取消要么降级到支持的版本。现在的错误信息完全没有办法定位到错误。

image

babelrc

image

webpack loaders

image

entry.index.js

image

代码片段如上,如果还需要什么信息我再提供。还请大家帮忙看一下问题,已经愁了我好几天,google都翻烂了,错误信息的位置在core-js,完全没有头绪,感激不尽,感激不尽。

react-router-redux 4.x 中的Object.defineProperty问题

你好,我看到react-router-redux 4.x 中发布的代码部分如下:

Object.defineProperty(exports, 'LOCATION_CHANGE', {
    enumerable: true,
    get: function get() {
      return _reducer.LOCATION_CHANGE;
    }
  });
  Object.defineProperty(exports, 'routerReducer', {
    enumerable: true,
    get: function get() {
      return _reducer.routerReducer;
    }
  });
....

这样的代码 哪怕用了polyfill 也没法兼容IE8了吧 ?

Is there a possibility to polyfill react 15?

(We won't actively remove IE 8–related code quite yet, but we will deprioritize new bugs that are reported. If you need to support IE 8 we recommend you stay on React v0.14.)

Officially it's said that IE8 is not supported but they will also not remove IE 8 related compatibility code. So there might be a chance that it still works with polyfills?

IE8,firstChild.data.length undefind

in IE8, this will be error.
<div id="etDiv"> <span>4444</span> <div class="abc"></div> </div> <script></script> <script type="text/javascript"> var a = document.getElementById("etDiv"); var b = a.firstChild; alert(b.data.length); </script>

because b.data is undefined in IE8

webpack-dev-server --inline --hot 报错

--hot 会生成一个 hotCreateRequire 的函数,其中有 indexOf,而 IE8 不支持

if(me.hot.active) {
/******/ 				if(installedModules[request]) {
/******/ 					if(installedModules[request].parents.indexOf(moduleId) < 0)
/******/ 						installedModules[request].parents.push(moduleId);
/******/ 					if(me.children.indexOf(request) < 0)
/******/ 						me.children.push(request);
/******/ 				} else hotCurrentParents = [moduleId];
/******/ 			}

react-ie8

run in ie8 。wrong at:‘extends’
babelHelpers.extends = Object.assign || function (target) {

MatchMedia error when run own tests

Pls, can you helpme?

Your project includes the enquirejs dependency. But I have issues when try to run tests into my project because

matchMedia not present, legacy browsers require a polyfill

I don't know how to solve this issue.

this is my code

import React from 'react';
import { shallow } from 'enzyme';
import { expect } from 'chai';

// Import components for testing here
import NavbarCrm from '../NavbarCrmComponent';

describe('<NavbarCrm />', function () {

  if (typeof window !== 'undefined') {
    var matchMediaPolyfill = function matchMediaPolyfill(mediaQuery) {
      return {
        media: mediaQuery,
        matches: false,
        addListener: function addListener() {},
        removeListener: function removeListener() {}
      };
    };
    window.matchMedia = window.matchMedia || matchMediaPolyfill;
  }

  it('should have props for heading and children', function (done) {
    const wrapper = shallow(<Menu />);
    expect(wrapper.props().classes).to.be.defined;
    expect(wrapper.props().children).to.be.defined;
    done();
  });
});

I tried in all methods. Above, below but the same error ever.

Can U help me?

I cant to solve the issue putting

if (typeof window !== 'undefined') {
    var matchMediaPolyfill = function matchMediaPolyfill(mediaQuery) {
      return {
        media: mediaQuery,
        matches: false,
        addListener: function addListener() {},
        removeListener: function removeListener() {}
      };
    };
    window.matchMedia = window.matchMedia || matchMediaPolyfill;
  }

I include the above code in the line 49826 located at andt.js file into my node_modules And the problem is over. but this is not a good solution.

into enquirejs/src/include/wrap.js into the dist file for npm installed module. But it isn't a pretty solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.