简体   繁体   English

当前未启用对实验语法“classProperties”的支持 (8:16)。 添加@babel/plugin-proposal-class-properties

[英]Support for the experimental syntax 'classProperties' isn't currently enabled (8:16). Add @babel/plugin-proposal-class-properties

I'm trying to compile my React Native App and I'm getting the following error:我正在尝试编译我的 React Native App,但出现以下错误:

SyntaxError: C:\Users\Ori\Desktop\Projects\React\my-app\node_modules@react-native-community\google-signin\src\GoogleSignin.js: Support for the experimental syntax 'classProperties' isn't currently enabled (8:16) SyntaxError: C:\Users\Ori\Desktop\Projects\React\my-app\node_modules@react-native-community\google-signin\src\GoogleSignin.js:目前未启用对实验性语法“classProperties”的支持(8:16)

Add @babel/plugin-proposal-class-properties ( https://git.io/vb4SL ) to the 'plugins' section of your Babel config to enable transformation.将 @babel/plugin-proposal-class-properties ( https://git.io/vb4SL ) 添加到 Babel 配置的“插件”部分以启用转换。

If I understand correctly, since it is a react native app, the.babelrc file is ignored, but there are still some ways to overcome that.如果我理解正确,因为它是一个反应原生应用程序,.babelrc 文件被忽略,但仍有一些方法可以克服它。 I have seen a few solutions on the web but none seem to work for me.我在 web 上看到了一些解决方案,但似乎没有一个对我有用。

I've tried:我试过了:

  • adding babel.config.js with in the same folder as package.json:在与 package.json 相同的文件夹中添加 babel.config.js:
module.exports = {
    presets: [
        '@babel/preset-env',
        '@babel/preset-react',
        '@babel/preset-typescript'
    ],
    plugins: [
        '@babel/plugin-proposal-class-properties'
    ]
};
  • adding babel configuration to package.json将 babel 配置添加到 package.json
{
    presets: [
        '@babel/preset-env',
        '@babel/preset-react',
        '@babel/preset-typescript'
    ],
    plugins: [
        '@babel/plugin-proposal-class-properties'
    ]
}
  • adding loose property to plugins:向插件添加松散属性:
"plugins": [
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ]
  ]

nothing seems to work.似乎没有任何效果。


My code:我的代码:

package.json: package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.5.0",
    "@material-ui/icons": "^4.4.3",
    "@react-native-community/google-signin": "^3.0.1",
    "jquery": "^3.4.1",
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "react-ga": "^2.7.0",
    "react-native-google-signin": "^2.1.0",
    "react-scripts": "3.2.0"
  },
  "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"
    ]
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      [
        "@babel/plugin-proposal-class-properties",
        {
          "loose": true
        }
      ]
    ]
  },
  "devDependencies": {
    "@babel/cli": "^7.6.4",
    "@babel/core": "^7.6.4",
    "@babel/plugin-proposal-class-properties": "^7.5.5"
  }
}

babel.config.js: babel.config.js:

module.exports = {
    plugins: [
        ['@babel/plugin-proposal-decorators', { legacy: true }],
        ['@babel/plugin-proposal-class-properties', { loose: true }],
        '@babel/plugin-syntax-dynamic-import',
        '@babel/plugin-transform-regenerator',
        [
            '@babel/plugin-transform-runtime',
            {
                helpers: false,
                regenerator: true,
            },
        ],
    ],
    presets: [
        "@babel/preset-flow",
        'module:metro-react-native-babel-preset',
    ],
};

If anyone can shine a light on the issue that would be great, Thank you!如果有人能阐明这个问题,那就太好了,谢谢!

According to [this GitHub][1] issue if you using create-react-app you should copy your .babelrc or babel.config.js configurations to webpack.config.js and delete those.because of htis two line of code babelrc: false,configFile: false, your config in babelrc,.. are useless.根据 [this GitHub][1] 问题,如果您使用 create-react-app,您应该将.babelrcbabel.config.js配置复制到webpack.config.js并删除这些。因为 htis 有两行代码babelrc: false,configFile: false,你在 babelrc 中的配置,.. 没用。 and your webpack.config.js is in your./node_madules/react-scripts/config folder.并且您的 webpack.config.js 在您的 ./node_madules/react-scripts/config 文件夹中。 you can solve the problem like this:你可以像这样解决问题:

{
              test: /\.(js|mjs)$/,
              exclude: /@babel(?:\/|\\{1,2})runtime/,
              loader: require.resolve('babel-loader'),
              options: {
                babelrc: false,
                configFile: false,
                compact: false,
                presets: [
                  [
                    require.resolve('babel-preset-react-app/dependencies'),
                    { helpers: true },

                  ],
                  '@babel/preset-env', '@babel/preset-react'
                ],
                plugins: ['@babel/plugin-proposal-class-properties'],
                .
                .
                .

or you can change babelrc: false,configFile: false, to true according to your config file.或者您可以根据您的配置文件将babelrc: false,configFile: false,更改为 true。 or you can eject and do this.或者您可以弹出并执行此操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 @babel/plugin-proposal-class-properties 仍然失败,“classProperties 当前未启用” - @babel/plugin-proposal-class-properties Still Fails with "classProperties isn't currently enabled" 使用 Jest、Babel、Webpack 和 React 进行测试。 当前未启用对实验性语法“classProperties”的支持 - Testing with Jest, Babel, Webpack, and React. Support for the experimental syntax 'classProperties' isn't currently enabled Laravel:当前未启用对实验语法“classProperties”的支持 - Laravel: Support for the experimental syntax 'classProperties' isn't currently enabled @ babel / plugin-proposal-class-properties不起作用 - @babel/plugin-proposal-class-properties doesn't work 如何解决问题当前未启用对实验性语法“classProperties”的支持 - How to solve the problem Support for the experimental syntax 'classProperties' isn't currently enabled “松散”:true 未修复当前未启用对实验性语法“classProperties”的支持 - "loose": true is not fixing Support for the experimental syntax 'classProperties' isn't currently enabled React.js 当前未启用对实验性语法“classProperties”的支持错误 - Support for the experimental syntax 'classProperties' isn't currently enabled error on a React.js 错误:找不到模块“@babel/plugin-proposal-class-properties” - Error: Cannot find module '@babel/plugin-proposal-class-properties' 带有 Babel 的 ESLint:在 .eslintrc 中未找到声明的 plugin-proposal-class-properties - ESLint with Babel: plugin-proposal-class-properties not found declared in .eslintrc Babel-Standalone 错误:内联 Babel 脚本:当前未启用对实验性语法“decorators-legacy”的支持 (14:1): - Babel-Standalone Error : Inline Babel script: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (14:1):
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM