带Typescript的create-react-app:当前未启用对实验语法'classProperties'的支持

时间:2019-12-26 16:48:28

标签: reactjs typescript babel react-create-app

我用npx create-react-app my-app --template typescript创建了一个React应用,并添加了React组件rn-sliding-up-panel。我知道rn代表react native,但是解决方案是纯js,并且可以在网络上正常工作。

现在我得到Support for the experimental syntax 'classProperties' isn't currently enabled (35:20): Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.

这是一条很棒的信息错误消息。不幸的是,我没有babel配置,因为我想用打字稿进行整个翻译。

我已经尝试将配置添加到我的package.json中,但是运气不好

{
  "name": "slider-test",
  "version": "0.1.0",
  "private": true,
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
  },
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "@types/jest": "^24.0.24",
    "@types/node": "^12.12.21",
    "@types/react": "^16.9.16",
    "@types/react-dom": "^16.9.4",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0",
    "rn-sliding-up-panel": "^2.4.0",
    "typescript": "^3.7.3"
  },
  "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"
    ]
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.7.4"
  }
}

我该如何解决?

0 个答案:

没有答案