ecmascript-6 - 使用 NextJS 定位边缘时,不会转译 Rest-spread
问题描述
我正在尝试通过 Babel 转换我的 ES6 代码,我正在使用next/babel
预设,preset-env
并且正在使用browsers: defaults
目标。
NextJS 预设包含@babel/plugin-proposal-object-rest-spread
在其插件数组中,我想知道为什么在边缘测试时出现错误Expected identifier, string or number
,并且在编译的 JS 中查找错误时,我看到它在发生时{...t}
发生。
这是我的babel.config.js
:
module.exports = {
presets: [
[
'next/babel',
{
'@babel/preset-env': {
targets: {
browsers: 'defaults'
},
useBuiltIns: 'usage'
}
}
]
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
['styled-components', { ssr: true, displayName: true, preprocess: false }],
[
'module-resolver',
{
root: ['.', './src']
}
]
],
env: {
development: {
compact: false
}
}
};
对此的任何帮助将不胜感激!
解决方案
最后,我的问题与 babel 未转译的包有关。我的解决方案是使用 NextJS 的next-transpile-modules插件让 babel 将包代码转换成可以在我需要的浏览器上运行的东西。
这是我的 NextJS webpack 配置的示例,其中指定了我需要转译的包:
const withTM = require('next-transpile-modules');
module.exports = withTM({
transpileModules: ['swipe-listener']
});
推荐阅读
- javascript - 在 JavaScript 中将已兑现的文件重新加载到浏览器 serviceWorker
- javascript - 如何修改 codemirror 的自动完成功能
- c++ - C++ 命名空间警告 - 声明隐藏全局声明 VS 2015 警告 C4459
- project-reactor - 线程在反应器执行中是否曾经更改过一次?
- string - Haskell 最后一个字符串
- java - 如何在不同的方法中使用arraylist,但方法在类内部
- php - PHP preg_match 检查文件名以括号数字结尾(例如文件名(1).pdf)
- regex - Using re.finditer to generate iterative object, but no return, the regex code is ok when testing separately
- syntax-error - 寻求帮助以纠正我的 Verilog 代码中的语法错误
- tiddlywiki5 - 从 javascript 访问 JSON Tiddler 的标准方法