简体   繁体   English

“松散”:true 未修复当前未启用对实验性语法“classProperties”的支持

[英]"loose": true is not fixing Support for the experimental syntax 'classProperties' isn't currently enabled

Support for the experimental syntax 'classProperties' isn't currently enabled当前未启用对实验性语法“classProperties”的支持

I tried the solutions still get the error after re building.我尝试了重新构建后的解决方案仍然出现错误。

Support for the experimental syntax 'classProperties' isn't currently enabled 当前未启用对实验性语法“classProperties”的支持

package.json包.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 .babelrc

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

I am using plugin-proposal-class-propterties and it works, here is my JSON configuration file .babelrc我正在使用plugin-proposal-class-propterties并且它有效,这是我的 JSON 配置文件.babelrc

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

Try making a file babel.config.js and using module.exports to export the configuration.尝试创建一个文件babel.config.js并使用module.exports导出配置。 I also believe you don't require the loose option:我也相信你不需要loose选择:

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

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

you must install你必须安装

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

and

change entry and output更改输入和输出


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"
            ]
          }
        }]
      }
    ]
  }
}

暂无
暂无

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

相关问题 Laravel:当前未启用对实验语法“classProperties”的支持 - Laravel: Support for the experimental syntax 'classProperties' isn't currently enabled 如何解决问题当前未启用对实验性语法“classProperties”的支持 - How to solve the problem 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 使用 Jest、Babel、Webpack 和 React 进行测试。 当前未启用对实验性语法“classProperties”的支持 - Testing with Jest, Babel, Webpack, and React. Support for the experimental syntax 'classProperties' isn't currently enabled 当前未启用对实验语法“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 如何解决当前未启用对实验语法“jsx”的支持 - How to solve Support for the experimental syntax 'jsx' isn't currently enabled 错误:当前未启用对实验性语法“可选链”的支持,但已启用 - Error: Support for the experimental syntax 'optionalChaining' isn't currently enabled, but it is Expo 目前未启用对实验语法“jsx”的支持 - Expo Support for the experimental syntax 'jsx' isn't currently enabled Rails 上的 Ruby “当前未启用对实验语法 'jsx' 的支持” - Ruby on Rails "support for the experimental syntax 'jsx' isn't currently enabled" Angular 13 - 当前未启用对实验语法“importMeta”的支持 - Angular 13 - Support for the experimental syntax 'importMeta' isn't currently enabled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM