Babel 无法识别 ... 在语法中。 (还原)
Babel can't recognize ... in syntax. (Redux)
Babel 无法转换我的 Redux reducer 中的 ...。当 运行 Webpack with Babel:
时,我不断收到错误消息
ERROR in ./src/reducers/api_reducer.js
Module build failed: SyntaxError: Unexpected token (18:15)
16 | switch(action.type) {
17 | case FETCH_MESSAGE:
> 18 | return { ...state, message: action.payload };
| ^
19 | case FETCH_EVENTS:
20 | return { ...state, eventList: action.payload };
21 | case CREATE_EVENT:
这些是我安装的依赖项:
"devDependencies": {
"babel-core": "^6.17.0",
"babel-loader": "^6.2.0",
"babel-preset-env": "^1.1.4",
"babel-preset-react": "^6.16.0",
"css-loader": "^0.26.1",
"file-loader": "^1.1.4",
"html-webpack-plugin": "^2.30.1",
"image-webpack-loader": "^3.4.2",
"rimraf": "^2.6.2",
"style-loader": "^0.13.1",
"url-loader": "^0.5.9",
"webpack": "2.2.0-rc.0",
"webpack-dev-server": "^2.2.0-rc.0"
}
我的 .babelrc 是这样的:
{
"presets": ["babel-preset-env", "react"]
}
谁能告诉我为什么...无法转译?你是如何解决这个问题的? -非常感谢!
使用transform-object-rest-spread
babel 的插件。
Transform rest properties for object destructuring assignment and spread properties for object literals
您正在使用 object spread operator which is currently a stage-3 feature. They are not supported by babel-preset-env. You need to add babel-preset-stage-3。
对象 rest/spread 目前是第 3 阶段提案,因此未包含在 babel-preset-env
中。您可以:
仅包含此特定转换 .babelrc
:
{
"plugins": ["transform-object-rest-spread"]
}
包括所有第 3 阶段提案:
{
"presets": ["env", "react", "stage-3"]
}
Babel 无法转换我的 Redux reducer 中的 ...。当 运行 Webpack with Babel:
时,我不断收到错误消息ERROR in ./src/reducers/api_reducer.js
Module build failed: SyntaxError: Unexpected token (18:15)
16 | switch(action.type) {
17 | case FETCH_MESSAGE:
> 18 | return { ...state, message: action.payload };
| ^
19 | case FETCH_EVENTS:
20 | return { ...state, eventList: action.payload };
21 | case CREATE_EVENT:
这些是我安装的依赖项:
"devDependencies": {
"babel-core": "^6.17.0",
"babel-loader": "^6.2.0",
"babel-preset-env": "^1.1.4",
"babel-preset-react": "^6.16.0",
"css-loader": "^0.26.1",
"file-loader": "^1.1.4",
"html-webpack-plugin": "^2.30.1",
"image-webpack-loader": "^3.4.2",
"rimraf": "^2.6.2",
"style-loader": "^0.13.1",
"url-loader": "^0.5.9",
"webpack": "2.2.0-rc.0",
"webpack-dev-server": "^2.2.0-rc.0"
}
我的 .babelrc 是这样的:
{
"presets": ["babel-preset-env", "react"]
}
谁能告诉我为什么...无法转译?你是如何解决这个问题的? -非常感谢!
使用transform-object-rest-spread
babel 的插件。
Transform rest properties for object destructuring assignment and spread properties for object literals
您正在使用 object spread operator which is currently a stage-3 feature. They are not supported by babel-preset-env. You need to add babel-preset-stage-3。
对象 rest/spread 目前是第 3 阶段提案,因此未包含在 babel-preset-env
中。您可以:
仅包含此特定转换
.babelrc
:{ "plugins": ["transform-object-rest-spread"] }
包括所有第 3 阶段提案:
{ "presets": ["env", "react", "stage-3"] }