Lerna反应通用库“当前未启用对实验语法'classProperties'的支持”错误

时间:2019-09-27 21:14:14

标签: webpack babel create-react-app lerna monorepo

我正在尝试使用一些create-react-app应用和一个公共库来构建一个lerna monorepo。

我正在跟踪that link中的脚本

一切正常,我可以访问创建的monorepo通用对象,但是在尝试使用babel时卡住了。

我的常用组件使用propTypes,但出现以下错误:

Failed to compile.

../webcommon/src/components/app/App/App.js
SyntaxError: /Volumes/DADOS/dev/workspace/dev/packages/webcommon/src/components/app/App/App.js: Support for the experimental syntax 'classProperties' isn't currently enabled (39:19):

  37 |
  38 | class App extends Component {
> 39 |  static propTypes = {
     |                   ^
  40 |      router: PropTypes.object.isRequired,
  41 |      module: PropTypes.string.isRequired,
  42 |      menuConfig: PropTypes.object

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.

我试图做所需的事情,所以我的webcommon库中有以下package.json:

{
  "name": "@monorepo/webcommon",
  "version": "0.0.0",
  "keywords": [],
  "main": "lib/webcommon.js",
  "directories": {
    "lib": "lib",
    "test": "__tests__"
  },
  "files": [
    "lib"
  ],
  "publishConfig": {
    "access": "public"
  },
  "scripts": {
    "test": "echo \"Error: run tests from root\" && exit 1"
  },
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.5.5",
    "@babel/preset-env": "^7.6.2",
    "@babel/preset-react": "^7.0.0"
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      [
        "@babel/plugin-proposal-class-properties"
      ]
    ]
  }
}

仍然出现相同的错误。我的主要项目(正在调用通用组件)package.json

{
  "name": "admin",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@monorepo/webcommon": "^0.0.0",
    "react": "^16.10.0",
    "react-dom": "^16.10.0",
    "react-scripts": "3.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

如何解决给定的问题并在公用组件上使用propTypes

0 个答案:

没有答案