新鲜的react-create-app的react-styleguidist错误?

时间:2019-01-21 14:04:39

标签: reactjs babeljs react-styleguidist

尝试为基于React的项目设置文档。

使用来自“ create-react-app”的新“ my-app”和一个非常幼稚的* .js文件,我得到一个错误:

C:\xampp\htdocs\my-app2\node_modules\react-styleguidist\bin\styleguidist.js
You can now view your style guide in the browser:

  Local:            http://localhost:6060/
  On your network:  http://10.100.11.165:6060/

 FAIL  Failed to compile

./src/src/topnav/topnav.js
SyntaxError: C:\xampp\htdocs\my-app2\src\src\topnav\topnav.js: Support for the experimental syntax 'classProperties' isn't currently enabled (8:20):

   6 |  */
   7 | export default class Button extends React.Component {
>  8 |   static propTypes = {
     |                    ^
   9 |     /** Description of prop "foo". */
  10 |     foo: PropTypes.number,
  11 |     /** Description of prop "baz". */

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
 @ ./node_modules/react-styleguidist/lib/index.js (./node_modules/react-styleguidist/loaders/styleguide-loader.js!./node_modules/react-styleguidist/lib/index.js) 46:30-89
 @ ./node_modules/react-styleguidist/lib/index.js
 @ multi ./node_modules/react-styleguidist/lib/index ./node_modules/react-styleguidist/node_modules/react-dev-utils/webpackHotDevClient.js

有人熟悉这个错误吗?

我怀疑此修复程序与Babel有某种联系,但是,我无法从以前的查询中解决它。

1 个答案:

答案 0 :(得分:1)

@babel/plugin-proposal-class-properties上添加.babelrc,在@babel/plugin-proposal-class-properties上添加package.json,该错误也会显示



.babelrc

 {
      "presets": [
        "@babel/preset-env",
        "@babel/preset-react"
      ],
      "plugins": [
        "@babel/plugin-proposal-class-properties"
       ]
    }

package.json

"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
...