我使用create-react-app创建了一个React应用。
运行弹出命令后,无法按以下方式使用散布运算符:
//eslint-disable-next-line
const { children, ...attributes } = this.props; //Line 19
运行yarn start时,总是会出现此错误
第19行:解析错误:意外的令牌..
Webpack开发服务器 我尝试将所有预设和转换插件都添加到webpack开发服务器配置和.babelrc中,但是没有运气
// Process JS with Babel.
{
test: /\.(js|jsx|mjs)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
presets:['react','es2015','env',"stage-2"],
plugins: ["transform-object-rest-spread"],
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
},
},
// "postcss" loader app
在babel rc文件中也是如此 //。babelrc
{
"presets":["env","react","stage-2"],
"plugins": [
["transform-object-rest-spread", { "useBuiltIns": true }]
]
}
如果我不弹出脚本,效果很好。
答案 0 :(得分:2)
所以问题原来是拖拖拉拉。 Webpack配置在babel之前加载
添加解析器选项可修复该问题。
{
test: /\.(js|jsx|mjs)$/,
enforce: 'pre',
use: [
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve('eslint'),
"extends": "airbnb",
"parserOptions":{
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
}
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
},
答案 1 :(得分:0)
使用以下内容更新了@babel: npm install @ babel / runtime @ latest完成了工作