当我尝试通过 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/