我正在清理一个较旧的项目并将前端的 Angular 升级到 12,并且我从 IxJS 获得了一堆构建,这是一个已经存在一段时间的库:
./node_modules/ix/asynciterable/asynciterablex.mjs:31:10 - Error: Module parse failed: Unexpected token (31:10) File was processed with these loaders: * ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js You may need an additional loader to handle the result of these loaders. | let i = 0; | > for await (const item of source) { | yield projection.call(thisArg, item, i++, signal); | }
即使在我刚刚使用 Angular CLI 生成的干净暂存器项目中也会发生这种情况,我只是将其放入app.component.ts
以确保它命中库:
import { Component } from '@angular/core';
import * as aix from 'ix/asynciterable';
import * as aixop from 'ix/asynciterable/operators';
async function* source() {
yield 1;
yield 2;
yield 3;
}
async function title(): Promise<string> {
const parts = [];
for await (const y of aix
.from(source())
.pipe(aixop.map(async (x) => x * 2))) {
parts.push(String(y));
}
return parts.join();
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
title = 'ng-scratch';
world!: Promise<string>;
ngOnInit() {
this.world = title();
}
}
并将其输出app.component.html
:
Hello, {{world | async}}
奇怪的是,它只报告来自库的错误;如果我将title()
功能更改为:
async function title(): Promise<string> {
const parts = [];
for await (const y of source()) {
parts.push(String(y));
}
return parts.join();
}
有没有办法解决这个问题?