Laravel:目前未启用对实验性语法 'classProperties' 的支持
Laravel: Support for the experimental syntax 'classProperties' isn't currently enabled
在我的 resource/app.js 中,我需要自己编写的验证脚本。我在编译 (npm 运行 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):
我的文件:
app.js
require('./bootstrap');
require('./myvendor/small-form-validator');
/resources/js/myvendor/small-form-validator.js
class SmallFormValidator {
errMsgs = {
required: 'This field is required!',
string: 'Not valid string.',
...
我的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"
}
}
系统报错errMsgs = {...}后的赋值运算符(="字符)。
问题是我用 Class 风格而不是原型风格写我的 javascript 吗?
已更新
我的解决方案是在根目录中创建一个新的 .babelrc 文件,其中包含加载 Babel plugin-proposal-class-properties 插件的命令。
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
看codedge的正确答案!
您需要在项目的根目录中创建一个.babelrc
并添加
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
然后运行 npm install --save-dev @babel/plugin-proposal-class-properties
安装包然后npm run watch
(分别npm run dev
)编译一切。
在我的 resource/app.js 中,我需要自己编写的验证脚本。我在编译 (npm 运行 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):
我的文件:
app.js
require('./bootstrap');
require('./myvendor/small-form-validator');
/resources/js/myvendor/small-form-validator.js
class SmallFormValidator {
errMsgs = {
required: 'This field is required!',
string: 'Not valid string.',
...
我的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"
}
}
系统报错errMsgs = {...}后的赋值运算符(="字符)。
问题是我用 Class 风格而不是原型风格写我的 javascript 吗?
已更新
我的解决方案是在根目录中创建一个新的 .babelrc 文件,其中包含加载 Babel plugin-proposal-class-properties 插件的命令。
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
看codedge的正确答案!
您需要在项目的根目录中创建一个.babelrc
并添加
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
然后运行 npm install --save-dev @babel/plugin-proposal-class-properties
安装包然后npm run watch
(分别npm run dev
)编译一切。