ReactJS - SCRIPT1010: Expected identifier - Production build not running on IE11

前端 未结 4 1536
失恋的感觉
失恋的感觉 2020-12-10 04:13

I created a new project with create-react-app today. The production build is not running fine on IE11, the console shows following error:

SCRIPT1010: Expected

相关标签:
4条回答
  • 2020-12-10 04:36

    Here is how I fixed it. Not to forget Mr React "Dan Abramov" helped me in this.

    So the issue is by default the application was being rendered on IE7 that is not on only IE IE11/EDGE that support the transpiled build. So I had to mention the meta information to let browser know that the intended browser is IE11/edge. Add this in the head section of your index.html:

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    

    Now as I got, you ay also see some error in console that reads:

    SCRIPT5009: 'Set' is undefined
    

    Not to worry, there is a way around that as well: https://reactjs.org/docs/javascript-environment-requirements.html

    Here is the issue I discussed with Dan on git: https://github.com/facebook/create-react-app/issues/4255

    0 讨论(0)
  • 2020-12-10 04:40

    It seems like the order of polyfills is also a factor. There are several solutions in this issue that could help resolve this. https://github.com/facebook/react/issues/8379

    0 讨论(0)
  • 2020-12-10 04:47

    This is IE problem, not react framework.

    the problem that "default" is a reserved word on IE

    you can rename "default" function to a new name or use javascript function as :

    return e["default"]
    
    0 讨论(0)
  • 2020-12-10 04:52

    You need to include babel-polyfills and transpile down to ES5 for IE11 to work.

    React 16 depends on the collection types Map and Set. If you support older browsers and devices which may not yet provide these natively (e.g. IE < 11) or which have non-compliant implementations (e.g. IE 11), consider including a global polyfill in your bundled application, such as core-js or babel-polyfill.

    https://reactjs.org/docs/javascript-environment-requirements.html

    You can include a polyfill via webpack like so

    entry: {
          app: [
            'babel-polyfill',
            'react-hot-loader/patch',
            'react',
            'react-dom',
            './src/index.web.tsx',
          ]
    },
    
    0 讨论(0)
提交回复
热议问题