关于“Class private methods are not enabled.”问题

在编写个人博客时遇到模块构建失败的错误,具体是关于Babel不支持类的私有方法。通过搜索解决方案,发现是Babel配置问题。添加了`@babel/plugin-transform-private-methods`插件并设置`loose`为`true`,同时调整了其他相关Babel插件配置,最终解决了这个问题。
摘要由CSDN通过智能技术生成

在编写个人博客的时候莫名其妙遇到了如下问题:

Module build failed (from ./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib/index.js):
SyntaxError: D:\VSCODE\building\project_all_1.1\project1.1\node_modules\marked\lib\marked.esm.js: Class private methods are not enabled. Please add `@babel/plugin-transform-private-methods` to your configuration.

在网上搜了很多答案,能了解到是babel配置问题,因此又使用了一些方法。

最初我以为是因为marked模块导入方式的不正确或者是模块其他的问题,最后我简单修改了脚手架中的babel.config.js才最终消除报错,修改之后的配置如下:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],
  plugins: [
    ["@babel/plugin-transform-private-methods",{"loose":true}],
    ["@babel/plugin-transform-class-properties", {
      "loose": true
    }],
    ["@babel/plugin-transform-private-property-in-object", {
      "loose": true
    }]
  ]

}

 我也不是很懂具体的配置信息,主要是修改了其中的loose:true属性,最终才消除了问题。

Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable. To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime. During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream. When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object. Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures: private void writeObject(java.io.ObjectOutputStream out) throws IOException private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException; private void readObjectNoData() throws ObjectStreamException;
07-23
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值