[英]"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.