节点JS意外字符#
。
类:
export class Test{
#parent = null;
#name = null;
constructor(name, parent) {
this.#name = name;
if (parent) {
this.#parent = parent;
}
}
}
.babelrc:
{
"presets": [
"@babel/preset-env"
]
}
package.json:
"start": "babel-node"
我正在运行脚本"start“,并得到这个错误:
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
如何修复它?
发布于 2020-04-25 22:56:58
从"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"
]
https://stackoverflow.com/questions/61427567
复制相似问题