webpack和babel项目使用ES6装饰器错误:Decorators are not supported yet in 6.x pending proposal update.

在webpack和babel项目中,使用ES6装饰器decorator时出错,错误信息如下:

Decorators are not supported yet in 6.x pending proposal update.

Webpack的相关配置如下:

loaders: [
  {
    loader: 'babel',
    exclude: /node_modules/,
    include: path.join(__dirname, 'src'),
    test: /\.jsx?$/,
    query: {
      plugins: ['transform-runtime'],
      presets: ['es2015', 'stage-0', 'react']
    }
  }
]

解决办法

1、安装babel插件

npm i --save-dev babel-plugin-transform-decorators-legacy

2、在.babelrc或webpack中配置该插件

.babelrc配置:

{
  "presets": ["es2015", "stage-0", "react"],
  "plugins": [
    ["transform-decorators-legacy"],
    // ...
  ]
}

Webpack配置:

{
  test: /\.jsx?$/,
  loader: 'babel',
  query: {
    cacheDirectory: true,
    plugins: ['transform-decorators-legacy' ],
    presets: ['es2015', 'stage-0', 'react']
  }
}

3、使用React Native的情况

使用react-native时,需要安装如下插件:

npm i --save babel-preset-react-native-stage-0

.babelrc配置如下:

{
  "presets": ["react-native-stage-0/decorator-support"]
}

来源:

https://www.srcmini02.com/1799.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_42400.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?