如果已启用,如何修复“当前未启用对实验语法 'classProperties' 的支持”错误?

Posted

技术标签:

【中文标题】如果已启用,如何修复“当前未启用对实验语法 \'classProperties\' 的支持”错误?【英文标题】:How to fix "Support for the experimental syntax 'classProperties' isn't currently enabled" error if it has been already enabled?如果已启用,如何修复“当前未启用对实验语法 'classProperties' 的支持”错误? 【发布时间】:2019-12-12 00:15:30 【问题描述】:

我正在从这个示例 https://github.com/brunolemos/react-native-web-monorepo 构建一个用于 Web、androidios 的跨平台 monorepo 应用程序,当我将 React Native Base 添加到我的项目中时,我根据本指南 https://docs.nativebase.io/docs/GetStarted.html 更改了我的 config-overrides.jsWeb

但在那之后我得到了 SyntaxError: C:\Users\maksi\Desktop\ecmsk\node_modules\native-base\node_modules\react-native-vector-icons\lib\create-icon-set-from-fontawesome5.js: Support for the experimental syntax 'classProperties' isn't currently enabled 错误。

我尝试将loose 选项添加到@babel/plugin-proposal-class-properties 插件,但没有奏效。我还尝试将plugins 添加到我的package.json 中,但也没有用。

package.json


  "name": "web",
  "version": "0.0.1",
  "private": true,
  "dependencies": 
    "@types/history": "^4.7.2",
    "@types/js-cookie": "^2.2.2",
    "@types/react": "^16.8.23",
    "@types/react-redux": "^7.1.1",
    "@types/redux-api-middleware": "^3.0.1",
    "connected-react-router": "^6.5.2",
    "history": "^4.9.0",
    "js-cookie": "^2.2.0",
    "native-base": "^2.13.4",
    "react": "16.8.4",
    "react-art": "^16.8.6",
    "react-dom": "16.8.4",
    "react-native-elements": "^1.1.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-web": "0.10.0",
    "react-redux": "^7.1.0",
    "react-router": "^5.0.1",
    "react-scripts": "2.1.8",
    "redux": "^4.0.4",
    "redux-api-middleware": "^3.0.1"
  ,
  "scripts": 
    "compile": "tsc -b",
    "prestart": "npm run compile",
    "start": "concurrently \"npm run compile -- -w\" \"npm run _start\"",
    "_start": "react-app-rewired start",
    "prebuild": "npm run compile",
    "build": "react-app-rewired build",
    "pretest": "npm run compile",
    "test": "react-app-rewired test",
    "eject": "react-app-rewired eject"
  ,
  "eslintConfig": 
    "extends": "react-app"
  ,
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": 
    "@babel/plugin-proposal-class-properties": "^7.5.5",
    "babel-plugin-react-native-web": "^0.11.5",
    "concurrently": "*",
    "customize-cra": "^0.4.1",
    "react-app-rewired": "^2.1.3",
    "typescript": "*"
  


config-overrides.js

const path = require('path');
const 
  override,
  addWebpackAlias,
  babelInclude,
  addBabelPlugins
 = require('customize-cra');

module.exports = override(
  addWebpackAlias(
    "react-native/Libraries/Renderer/shims/ReactNativePropRegistry": "react-native-web/dist/modules/ReactNativePropRegistry",
    "react-native": "react-native-web"
  ),
  babelInclude([
    path.resolve('src'),
    path.resolve('../components/src'),
    path.resolve('../../node_modules/native-base-shoutem-theme'),
    path.resolve('../../node_modules/react-navigation'),
    path.resolve('../../node_modules/react-native-easy-grid'),
    path.resolve('../../node_modules/react-native-drawer'),
    path.resolve('../../node_modules/react-native-safe-area-view'),
    path.resolve('../../node_modules/react-native-vector-icons'),
    path.resolve('../../node_modules/react-native-keyboard-aware-scroll-view'),
    path.resolve('../../node_modules/react-native-web'),
    path.resolve('../../node_modules/react-native-tab-view'),
    path.resolve('../../node_modules/static-container'),
  ]),
  addBabelPlugins(
    "@babel/plugin-proposal-class-properties"
  ),
);

【问题讨论】:

嘿,你解决过这个问题吗?我正在遵循来自 brunolemos 的相同示例,每当我尝试使用 yarn 将另一个库添加到 web 的 package.json 时,都会收到相同的错误。 同样的问题,回答会有很大帮助。谢谢! 这能回答你的问题吗? Support for the experimental syntax 'classProperties' isn't currently enabled 【参考方案1】:

问题可能是包含的路径。就我而言,我是这样的:

babelInclude([
    path.resolve('node_modules/react-native-typing-animation'),
    path.resolve('src')
])

路径是相对于 config.overrides 文件的。

【讨论】:

以上是关于如果已启用,如何修复“当前未启用对实验语法 'classProperties' 的支持”错误?的主要内容,如果未能解决你的问题,请参考以下文章

怎么给电脑打补丁?

usb mass storage device 设备无法启用是怎么回事啊?

如何使视图修复屏幕IOS 8?

如何修复“ObjectContext 实例已被处置”

如何修复“调试错误!,变量'x'周围的堆栈已损坏”?

如何禁用增量修复?