4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

babel実行時に「Support for the experimental syntax 'objectRestSpread' isn't currently enabled」と言われる場合の対応方法

Posted at

概要

古いパッケージをアップデートしたところビルド時にSupport for the experimental syntax 'classProperties' isn't currently enabledというエラーが出るようになったので対応方法を調べました.

ERROR in ./src/options/icons/clear.svg
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\hoge\src\options\icons\clear.svg: Support for the experimental syntax 'objectRestSpread' isn't currently enabled (6:3):

  4 | export default (({
  5 |   styles = {},
> 6 |   ...props
    |   ^
  7 | }) => React.createElement("svg", _extends({
  8 |   xmlns: "http://www.w3.org/2000/svg",
  9 |   viewBox: "0 0 24 24",

Add @babel/plugin-proposal-object-rest-spread (https://git.io/vb4Ss) to the 'plugins' section of your Babel config to enable transformation.

対応方法

1. @babel/plugin-proposal-object-rest-spreadをインストール

npm install -D @babel/plugin-proposal-object-rest-spread

2. babel.config.jsに次のように記述

babel.config.js
module.exports = {
  "plugins": ["@babel/plugin-proposal-object-rest-spread"]
}

.babelrcに記述しても効果がないので注意.
.babelrcwebpack.config.jsでbabelの設定をしている場合でも上の内容はbabel.config.jsに記述する必要がある.

.babelrcwebpack.config.jsbabel.config.jsは併用できるが,設定が分散するのが嫌な場合はbabel.config.jsにまとめるとよい.

環境

node: v8.11.4
@babel/core: 7.6.4
@babel/plugin-proposal-object-rest-spread: 7.6.2
react-svg-loader: 3.0.3

参考

https://github.com/babel/babel/issues/6970
https://github.com/babel/babel/issues/7879

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?