我有一个项目使用@mdx-js/runtime
,但是在IE 11或Edge (Edge 44.18362.449.0
)上完全崩溃了:
SCRIPT1028: SCRIPT1028: Expected identifier, string or number
实际上,这是因为这里使用了扩展语法:
const allNodes = sortedNodes.map(({ start: _, ...node }, i) => {
这行代码来自于
remark-mdx
,是@mdx-js/runtime
的一个依赖项,特别是这个文件和行:https://github.com/mdx-js/mdx/blob/master/packages/remark-mdx/extract-imports-and-exports.js#L66
我一直在尝试让Webpack和Babel转换该文件,以便不再使用spread。
Browserlist:
如果运行npx browserslist
,则可以看到IE 11存在。"browserslist": [
"> 0.5%",
"last 2 version",
"Firefox ESR",
"not dead",
"iOS >= 9"
]
.babelrc:
我曾尝试禁用loose
模式并添加@babel/plugin-transform-spread
和@babel/plugin-proposal-object-rest-spread
插件,但未解决问题。
{
"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:
我尝试显式地包含remark-mdx
和@mdx-js/runtime
,并且也尝试去除exclude
属性或将其更改为/node_modules\/(?!(remark-mdx|@mdx-js\/runtime)\/).*/
,但似乎都没有起作用:
{
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,
}
}],
}
我正在使用 Babel 7 和 Webpack 4。