When compiling my javascript files using npm run dev, I encountered a warning in my resource/app.js file where I require my custom validation script. The warning stated the following:
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):
Content of My Files:
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.',
...
Content of My 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 error was specifically related to the use of the assignment operator ("=") after errMsgs = {...}.
I wondered if the issue stemmed from writing my javascript in Class Style instead of Prototype Style.
Update:
To resolve this, I created a new .babelrc file in the root directory and added the configuration to load the Babel plugin-proposal-class-properties plugin.
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
Check out the correct solution provided by codedge!