[英]Module parse failed: Unexpected character '#' in an Angular Project
I am getting this error when I try to use private fields in an Angular Project.当我尝试在 Angular 项目中使用私有字段时出现此错误。
Error: ./src/app/_helpers/sample.js 6:11
Module parse failed: Unexpected character '#' (6:11)
File was processed with these loaders:
./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
./node_modules/@ngtools/webpack/src/ivy/index.js
./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
sample.js file:示例.js 文件:
class Sample {
constructor() {
this.#reloadConfig(); // 6th line
}
#reloadConfig() {
}
EDIT
: Was able to resolve it by upgrading Angular from 11 to 12, seems Angular 11 doesn't support private
methods declared in a JS file. EDIT
:能够通过将 Angular 从 11 升级到 12 来解决它,似乎 Angular 11 不支持在 JS 文件中声明的private
方法。
You just need to use private
keyword and remove the #您只需要使用private
关键字并删除 #
class Sample {
constructor() {
this.reloadConfig();
}
private reloadConfig() {
}
}
TypeScript's
private
-declared properties work with all targets — even ECMAScript 3! TypeScript 的private
声明属性适用于所有目标——甚至是 ECMAScript 3! — Microsoft DevBlog — 微软开发博客
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.