javascript - NPM 包中的类。当前未启用对实验语法“classProperties”的支持
问题描述
我创建了一个 npm 包,其中一个库包括“Employee.js”,如下所示:
class Employee{
name = null
}
在我放的 npm 包的 package.json 中
"babel": {
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
},
我有这些 babel 依赖项
"devDependencies": {
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.8",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.13.9"
}
每当我尝试在电子中运行它时,我都会收到此错误
./node_modules/xxx/xxx/Employee.js
Support for the experimental syntax 'classProperties' isn't currently enabled:
> 6 | name = null
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-class-properties (https://git.io/vb4yQ) to the 'plugins' section to enable parsing.
如何制作它以便我可以在文件中拥有类定义并且在导入包时不会导致此问题?
谢谢你。
解决方案
推荐阅读
- laravel - 使用 vuejs 和 laravel 将嵌套数据存储在文件中
- bash - 将 Xterm 的输出重定向到日志文件
- python - 尝试使用 Python 请求从 url 下载电子表格时获取登录页面
- javascript - 如何使用 jQuery 过滤处理多个数据属性?
- java - 节点作为反向代理限制了 java 后端的并发性
- javascript - 跳到 JSON 数组中的下一个对象并填充输入框
- c# - 使用事件触发器时 WPF Datagrid 的 OnGeneratingColumn 未触发
- azure - Azure 函数给出的不是有效的 Base-64 字符串错误
- reporting-services - SSRS 里程碑图表
- python - 如何将键/值对插入字典列表中包含的每个字典中