节点 JS 意外字符#。班级:export class Test{ #parent = null; #name = null; constructor(name, parent) { this.#name = name; if (parent) { this.#parent = parent; } }}.babelrc:{ "presets": [ "@babel/preset-env" ]}包.json:"start": "babel-node"我正在运行脚本“开始”并收到此错误:SyntaxError: Unexpected character '#' (9:4) 7 | 8 | export class Test{> 9 | #parent = null; | ^ 10 | #name = null;版本:-"@babel/core": "^7.8.7",-"@babel/node": "^7.8.7",-"@babel/preset-env": "^7.8.7",-node: v12.16.2-npm: 6.14.4怎么修?
1 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
从“stage-3”访问私有字段 - https://github.com/tc39/proposal-class-fields
您需要添加到 .babelrc:
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings"
]
添加回答
举报
0/150
提交
取消