I reproduce err in this project
following is my babel.config.js
module.exports = {
presets: [
["@babel/preset-env", {
"useBuiltIns": "usage",
"corejs": 3, // or 2,
"targets": {
"chrome": "54" // babel is for debug, it make code compatible android webview, so compatible my genymotion android webview is enough
},
"exclude": ["@babel/plugin-transform-regenerator", "@babel/plugin-transform-arrow-functions"]
}],
]
}
when npx webpack serve, it raise many similar errs like export 'default' (imported as 'stripAnsi') was not found in './modules/strip-ansi/index.js' (module has no exports)
when babel.config.js set chrome:54, it raise err; when set chrome:74, not err, but I expect all code support chrome 54 and I must use core-js to apply polyfill, so how to fix this bug?
Some deps use module.exports will conflict with babel + corejs, so make babel ignore these deps, and even no babel, most popular deps native support old browser(like react, react-dom use module.exports, they natively support very old browser)
in my case, only little deps cause this err, so i use babel.config.js "exclude" like following:
module.exports = {
presets: [
["@babel/preset-env", {
"useBuiltIns": "usage",
"corejs": "3.19.0", // or 2,
"targets": {
"android": "54" // babel is for debug, it make code compatible android webview, so compatible my genymotion android webview is enough
},
"exclude": ["@babel/plugin-transform-regenerator", "@babel/plugin-transform-arrow-functions"]
}],
"@babel/preset-react",
],
exclude: [/node_modules\/react/, /node_modules\/urijs/, /node_modules\/axios/]
}
also, if maybe deps cause this err, use babel.config.js "include" fix it