[英]Laravel: Support for the experimental syntax 'classProperties' isn't currently enabled
In my resource/app.js I require my own written validation script.在我的 resource/app.js 中,我需要自己编写的验证脚本。 I get the following warning when compiling ( npm run dev ) my javascript files.
编译( npm run dev )我的 javascript 文件时,我收到以下警告。
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /resources/js/myvendor/small-form-validator.js: Support for the experimental syntax 'classProperties' isn't currently enabled (2:13):
My Files:我的文件:
app.js应用程序.js
require('./bootstrap');
require('./myvendor/small-form-validator');
/resources/js/myvendor/small-form-validator.js /resources/js/myvendor/small-form-validator.js
class SmallFormValidator {
errMsgs = {
required: 'This field is required!',
string: 'Not valid string.',
...
My package.json我的 package.json
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"axios": "^0.21",
"bootstrap": "^4.0.0",
"jquery": "^3.2",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"postcss": "^8.1.14",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0"
}
}
The system complains about the assignment operator (" = " character) after errMsgs = {...}.系统抱怨 errMsgs = {...} 之后的赋值运算符(“ = ”字符)。
Is the problem that I wrote my javascript in Class Style instead of Prototype Style?问题是我在 Class 样式而不是原型样式中编写了我的 javascript 吗?
Updated更新
The solution in my case was to create in root an new.babelrc file with the order to load the Babel plugin-proposal-class-properties plugin.我的解决方案是在根目录中创建一个 new.babelrc 文件,其中包含加载 Babel plugin-proposal-class-properties 插件的顺序。
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
See the correct answear from codedge!请参阅 codedge 的正确答案!
You need to create a .babelrc
in the root of your project and add您需要在项目的根目录中创建一个
.babelrc
并添加
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
Then run npm install --save-dev @babel/plugin-proposal-class-properties
to install the package and then npm run watch
(respectively npm run dev
) to compile everything. Then run
npm install --save-dev @babel/plugin-proposal-class-properties
to install the package and then npm run watch
(respectively npm run dev
) to compile everything.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.