简体   繁体   English

Laravel:当前未启用对实验语法“classProperties”的支持

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

相关问题 如何解决问题当前未启用对实验性语法“classProperties”的支持 - How to solve the problem Support for the experimental syntax 'classProperties' isn't currently enabled “松散”:true 未修复当前未启用对实验性语法“classProperties”的支持 - "loose": true is not fixing 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