I have the webpack+babel setup for React JS project. It works well in Chrome browser but gives 'Syntax error' in IE. I believe this is due to babel polyfills, so I have followed numerous solutions(like - https://github.com/facebook/create-react-app/tree/master/packages/react-app-polyfill#polyfilling-other-language-features ) which I found which aren't working in my case though.
//package.json
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"not ie < 11",
"ie 11"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
},
"devDependencies": {
"@babel/core": "7.12.0",
"@babel/plugin-proposal-export-default-from": "7.12.1",
"@babel/plugin-transform-runtime": "7.12.1",
"@babel/preset-env": "7.12.10",
"@babel/preset-react": "7.10.4",
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/polyfill": "^7.12.1",
"@babel/preset-flow": "7.12.1",
"@babel/runtime-corejs3": "^7.12.5",
"react": "17.0.1",
"react-app-polyfill": "2.0.0",
"react-dom": "17.0.1",
}
// babel.config.js
module.exports = {
presets: [
['@babel/env', {
forceAllTransforms: true,
"targets": {
"browsers": [">0.25%", "not dead"]
}
} ],
"@babel/react"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-export-default-from"
]
};
// Index.js
import 'react-app-polyfill/ie11'
import 'react-app-polyfill/stable'
After this, cleared npm cache by
npm cache clear --force
and even tried deleting the node_modules and installing them again by npm install
but still getting the same error in IE 11:
Any pointers which might help over this
SCRIPT1002: Syntax error
in main.bundle.js