I have a project that uses @mdx-js/runtime
and it completely breaks on IE 11 or Edge (Edge 44.18362.449.0
):
SCRIPT1028: SCRIPT1028: Expected identifier, string or number
It actually breaks because of the spread syntax here:
const allNodes = sortedNodes.map(({ start: _, ...node }, i) => {
This line of code comes from remark-mdx
, which is a dependency of @mdx-js/runtime
, particularly this file and line: https://github.com/mdx-js/mdx/blob/master/packages/remark-mdx/extract-imports-and-exports.js#L66
I've been trying to get Webpack and Babel to transform that file so that the spread is no longer there:
Browserlist:
If I run npx browserslist
I can see IE 11 is there.
"browserslist": [
"> 0.5%",
"last 2 version",
"Firefox ESR",
"not dead",
"iOS >= 9"
]
.babelrc:
I've tried disabling loose
mode and adding @babel/plugin-transform-spread
and @babel/plugin-proposal-object-rest-spread
, but didn't fix the issue.
{
"presets": [[
"@babel/preset-env", {
"useBuiltIns": "usage",
"loose": false, // Was true before
"modules": "auto",
"corejs": 3
}],
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
["@babel/plugin-proposal-decorators", {
"legacy": true
}],
["@babel/plugin-proposal-class-properties", {
"loose": true
}],
"@babel/plugin-transform-spread", // Just added
"@babel/plugin-proposal-object-rest-spread", // Just added
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
"react-hot-loader/babel"
]
}
webpack.config.js:
Here I tried explicitly including remark-mdx
and @mdx-js/runtime
and also removing the exclude
property or changing it to /node_modules\/(?!(remark-mdx|@mdx-js\/runtime)\/).*/
, but nothing seems to work:
{
test: /\.(j|t)sx?$/,
include: [
path.resolve(__dirname, 'src'),
// Tried explicitly adding these 2:
path.resolve('node_modules/remark-mdx'),
path.resolve('node_modules/@mdx-js/runtime'),
],
// Tried removing `exclude` or not excluding those 2 packages:
// exclude: /node_modules/,
// exclude: /node_modules\/(?!(remark-mdx|@mdx-js\/runtime)\/).*/,
use: [{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: true,
}
}],
}
I'm using Babel 7 an Webpack 4.