由于意外字符 '#' 不在我的源代码中,因此 Angular 服务失败

标签 angular

当我尝试通过 Angular 应用程序构建时出现此错误:

ERROR in ./node_modules/blocking-proxy/built/lib/bin.js 1:0
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> #!/usr/bin/env node
| "use strict";
| Object.defineProperty(exports, "__esModule", { value: true });

有办法解决吗? 我已经删除了我的 node_modules 文件夹,但没有帮助。

这个组件似乎有问题:

树.component.ts :

import { Component, Input, Output } from '@angular/core';
import { EventEmitter } from 'protractor';

@Component({
    selector: 'app-tree',
    templateUrl: './tree.component.html',
    styleUrls: ['./tree.component.css']
})
/** wkz component*/
export class TreeComponent {
  @Input() wkz;
  @Output() notify = new EventEmitter();
    /** wkz ctor */
    constructor() {

    }
}

树.component.html

<div> test</div>

树.component.css

a{
    color:black;
}

此组件无处使用,仅在我的 app.module.ts 中引用:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './app.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
import { HomeComponent } from './home/home.component';
import { CounterComponent } from './counter/counter.component';
import { FetchDataComponent } from './fetch-data/fetch-data.component';
import { TreeComponent } from './tree/tree.component';
@NgModule({
  declarations: [
    AppComponent,
    NavMenuComponent,
    HomeComponent,
    CounterComponent,
    FetchDataComponent
  ],
  imports: [
    BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
    HttpClientModule,
    FormsModule,
    RouterModule.forRoot([
      { path: '', component: HomeComponent, pathMatch: 'full' },
      { path: 'counter', component: CounterComponent },
      { path: 'fetch-data', component: FetchDataComponent }
    ])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

最佳答案

您已经从 protactor 导入了 EventEmitter,它在构建时会抛出错误。

import { Component,EventEmitter,OnInit, Input, Output} from '@angular/core';

这通常发生在您尝试在不导入的情况下使用依赖项时。您的代码编辑器尝试添加它找到的导入以进行快速修复。

@Viswanatha Swamy 的回答也是一样的。只是我在一行中导入了所有依赖项

关于由于意外字符 '#' 不在我的源代码中,因此 Angular 服务失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60489687/

相关文章:

Angular2 innerHtml 绑定(bind)删除样式属性

javascript - 将 observable<object> 转换为 observable<task[]>

javascript - Angular 6 ng build --prod error "ERROR Error: ngIfElse must be a TemplateRef, but received ' true'。”

javascript - Angular2 形式 : validator with interrelated fields

javascript - 部署到 Github Pages 后不显示 Angular 图像

angular - 使用 ng-bootstrap 中的 anchor 路由到特定选项卡

ios - 在 IOS 上的 Ionic 3.9.2 中绑定(bind)文本/表单时无法滚动

angular - 如何将类型与动态导入一起使用?

javascript - 如何使用响应式(Reactive)表单向表单添加新控件而不出现错误 : "ERROR InternalError: "too much recursion"?

使用 Jasmine 进行 Angular5 测试。组件是 2 个模块 : AppModule and DynamicTestModule 声明的一部分