【问题标题】:"loose": true is not fixing Support for the experimental syntax 'classProperties' isn't currently enabled"loose": true is not fix 对实验性语法 'classProperties' 的支持当前未启用
【发布时间】:2019-11-10 18:35:32
【问题描述】:

目前不支持实验性语法“classProperties” 启用

我尝试了解决方案,重新构建后仍然出现错误。

Support for the experimental syntax 'classProperties' isn't currently enabled

package.json

{
  "name": "blahmodule",
  "version": "1.0.0",
  "description": "a fetch module for our project",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "./node_modules/.bin/babel src --out-file index.js"
  },
  "peerDependencies": {
    "react": "^16.6.6",
    "react-dom": "^16.6.3",
    "axios": "^0.19.0"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@babel/preset-react": "^7.0.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "axios": "^0.19.0"
  }
}

.babelrc

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

【问题讨论】:

    标签: javascript node.js express npm


    【解决方案1】:

    你必须安装

    npm install @babel/core @babel/plugin-proposal-class-properties @babel/preset-env @babel/preset-react babel-loader

    更改输入和输出


    const path = require('path')        
    module.exports = {
      entry: path.resolve(__dirname,'src', 'app.js'),
      output: {
        path: path.resolve(__dirname, "public","dist",'javascript'),
        filename: 'bundle.js'
      },
      module: {
        rules: [
          {
            test: /\.(jsx|js)$/,
            exclude: /node_modules/,
            use: [{
              loader: 'babel-loader',
              options: {
                presets: [
                  ['@babel/preset-env', {
                    "targets": "defaults"
                  }],
                  '@babel/preset-react'
                ],
                plugins: [
                  "@babel/plugin-proposal-class-properties"
                ]
              }
            }]
          }
        ]
      }
    }
    

    【讨论】:

      【解决方案2】:

      我正在使用plugin-proposal-class-propterties,它可以工作,这是我的 JSON 配置文件.babelrc

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

      【讨论】:

        【解决方案3】:

        尝试创建一个文件babel.config.js 并使用module.exports 导出配置。我也相信您不需要loose 选项:

        babel.config.js:

        module.exports = {
          presets: ["@babel/preset-env", "@babel/preset-react"],
          plugins: ["@babel/plugin-proposal-class-propterties"]
        };
        

        【讨论】:

        • 我得到.loose is not a valid Plugin property
        • 当我松手时它会生成,让我看看这是否能解决问题。
        • 所以也许你不需要loose 使用我上面描述的方法?等一下,正在编辑...
        • 解决方案仍然无法修复Support for the experimental syntax 'classProperties' isn't currently enabled
        猜你喜欢
        • 2019-02-13
        • 2020-03-06
        • 2022-10-22
        • 2020-08-07
        • 2021-04-26
        • 1970-01-01
        • 2020-11-10
        • 1970-01-01
        • 2021-05-17
        相关资源
        最近更新 更多