简体   繁体   English

模块解析失败:Angular 项目中出现意外字符“#”

[英]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.

相关问题 模块解析失败:意外字符 - Module parse failed: Unexpected character Webpack 4 - 模块解析失败:意外字符'@' - Webpack 4 - Module parse failed: Unexpected character '@' Gatsby - 模块解析失败:意外字符“�” - Gatsby - Module parse failed: Unexpected character '�' 获取错误:模块解析失败:...意外字符'#' - Getting Error: Module parse failed: … unexpected character '#' ModuleParseError:模块解析失败:意外字符“�” - ModuleParseError: Module parse failed: Unexpected character '�' Nuxt和Webpack:模块解析失败:意外字符' '(1:0] - Nuxt and Webpack: Module parse failed: Unexpected character '�' (1:0) CRA + Inversify @inject 模块解析失败:意外字符“@” - CRA + Inversify @inject Module parse failed: Unexpected character '@' next-images 错误:模块解析失败:意外字符“�” - next-images Error: Module parse failed: Unexpected character '�' webpack 4-模块解析失败:简单JS文件上出现意外字符' '(1:0) - webpack 4 - Module parse failed: Unexpected character '�' (1:0) on simple JS file 模块解析失败:将ttf添加到样式表时出现意外的字符''(1:0) - Module parse failed: Unexpected character '' (1:0) when adding ttf to my stylesheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM