Home  >  Article  >  Web Front-end  >  What should I do if IE cannot recognize react?

What should I do if IE cannot recognize react?

藏色散人
藏色散人Original
2022-11-09 15:26:071744browse

Solution to the problem that IE cannot recognize react: 1. Install "react-app-polyfill" and introduce it in "src/main.js"; 2. Configure parameters in "babel.config.js" ;3. Configure "transpileDependencies" in "vue.config.js".

What should I do if IE cannot recognize react?

The operating environment of this tutorial: Windows7 system, react17.0.1 version, Dell G3 computer.

What should I do if IE cannot recognize react?

Solutions for incompatible solutions when the react project is opened in IE11

Scenario 1:

What should I do if IE cannot recognize react?

1. Install react-app-polyfill

npm i react-app-polyfill  --save

2. Introduce it in src/main.js (need to be placed in the first line)

import 'react-app-polyfill/ie11'  
import 'react-app-polyfill/stable'

Scenario 2:

What should I do if IE cannot recognize react?

Solution: Configure parameters in babel.config.js

module.exports = {
  // https://www.babeljs.cn/docs/babel-preset-env
  presets: [
    // bable预设, 兼容于ie11的语法配置
    [
      '@babel/preset-env',
      // 支持的最低环境版本
      {
        targets: {
          ie: '11',
          chrome: '58',
        },
        // 只包含你所需要的 polyfill,  即按需加载
        useBuiltIns: 'usage',
        corejs: 3,
      },
    ],
    // 转换vue语法
    '@vue/cli-plugin-babel/preset',
    // 转换react语法
    '@babel/preset-react',
  ],
  plugins: [...]
}

Scenario 3:

What should I do if IE cannot recognize react?

Solution: Configure transpileDependencies in vue.config.js

ps: First understand the parameters of transpileDependencies

What should I do if IE cannot recognize react?

Because, react uses There are syntax errors in the plug-in, so just put the package name that needs to be translated

// vue.config.js
 
module.exports = {
  ...
  transpileDependencies: [
    'moment',
    'crypto-js',
    '@ecc',
    //  就是这两个
    'react-sortablejs',
    'react-contenteditable',
  ],
};

Recommended learning: "react video tutorial"

The above is the detailed content of What should I do if IE cannot recognize react?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn