在Angular V8中没有找到构建Web Worker的核心Angular对象



我正在Angular v8项目中做我的第一个web worker。我想让我的web工作者使HTTP服务调用,只是在那个单独的线程。不幸的是,在ng构建过程中,我得到了一个编译器错误,如下所示。特别是对于V6代码,我看到一些指南建议使用webpack。我写这些代码的时候,就好像Angular会把我的Typescript代码编译成一个javascript文件,把它放在正确的webpack中(如果相关的话),然后新的webworker()构造函数就会得到它需要的东西。

ERROR in ./src/app/modules/softlayer/bluereport-uploaders/report-uploader/softcopy-report-file-uploader.worker.ts (./node_modules/worker-plugin/dist/loader.js!./src/app/modules/softlayer/bluereport-uploaders/report-uploader/softcopy-report-file-uploader.worker.ts)
Module build failed (from ./node_modules/worker-plugin/dist/loader.js):
Error: node_modules/@angular/common/http/http.d.ts(1,1): error TS6053: File '/mnt/c/projects-new/cirrus-bluecost-rules-client/client/node_modules/@angular/common/http/http.ngfactory.ts' not found.
node_modules/@angular/core/core.d.ts(1,1): error TS6053: File '/mnt/c/projects-new/cirrus-bluecost-rules-client/client/node_modules/@angular/core/core.ngfactory.ts' not found.
node_modules/@angular/core/core.d.ts(1470,29): error TS2304: Cannot find name 'Element'.
node_modules/@angular/core/core.d.ts(1471,29): error TS2304: Cannot find name 'Element'.
node_modules/@angular/core/core.d.ts(1538,26): error TS2304: Cannot find name 'Node'.
node_modules/@angular/core/core.d.ts(1539,29): error TS2304: Cannot find name 'Node'.
node_modules/@angular/core/core.d.ts(6426,33): error TS2304: Cannot find name 'Node'.
node_modules/@angular/core/core.d.ts(9552,62): error TS2304: Cannot find name 'Element'.
node_modules/@angular/core/core.d.ts(9554,62): error TS2304: Cannot find name 'Node'.
node_modules/@angular/core/core.d.ts(9577,59): error TS2304: Cannot find name 'Element'.
node_modules/@angular/core/core.d.ts(10050,83): error TS2304: Cannot find name 'HTMLElement'.
node_modules/@angular/core/core.d.ts(13030,20): error TS2304: Cannot find name 'Document'.
node_modules/@angular/core/core.d.ts(13033,13): error TS2304: Cannot find name 'HTMLElement'.
node_modules/@angular/core/core.d.ts(13041,20): error TS2304: Cannot find name 'Document'.
node_modules/@angular/core/core.d.ts(13044,13): error TS2304: Cannot find name 'Document'.
node_modules/@angular/core/core.d.ts(13052,20): error TS2304: Cannot find name 'Document'.
node_modules/@angular/core/core.d.ts(13055,13): error TS2304: Cannot find name 'Window'.
src/app/core/services/softlayer.service.ts(1,1): error TS6053: File '/mnt/c/projects-new/cirrus-bluecost-rules-client/client/src/app/core/services/softlayer.service.ngfactory.ts' not found.
src/app/modules/softlayer/bluereport-uploaders/report-uploader/softcopy-report-file-uploader.worker.ts(16,37): error TS2339: Property 'data' does not exist on type 'Event'.
at AngularCompilerPlugin._update (/mnt/c/projects-new/cirrus-bluecost-rules-client/client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:776:31)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async AngularCompilerPlugin._make (/mnt/c/projects-new/cirrus-bluecost-rules-client/client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:667:13)

我的web worker文件是:

/// <reference lib="webworker" />
import { SoftlayerService } from '../../../../core/services/softlayer.service';
import { SpringBatchJobExecutionStatus } from '../../../../shared/models/SpringBatchJobExecutionStatus';
function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
function postMessageWithLog(message: SpringBatchJobExecutionStatus) {
console.log('Sending message back: ' + JSON.stringify(message));
postMessage(message);
}
self.addEventListener('message', ({ data }) => {
console.log('@@@ Begin addEventListener');
const softLayerService: SoftlayerService = data['softlayerService'];
const files: FileList = data['files'];
(async () => {
softLayerService.postAsyncFiles(files.item(0))
.subscribe((postAsyncFilesData: SpringBatchJobExecutionStatus) => {
console.log('@@@ http success handler for postAsyncFiles');
postAsyncFilesData.httpRequestSuccessful = true;
postMessageWithLog(postAsyncFilesData);
if (postAsyncFilesData.exitStatus === 'RUNNING' || postAsyncFilesData.batchStatus === 'STARTING') {
console.log('Beginning jobExecutionResult fetch loop');
let errorDetected = false;``
let jobExecutionResult = postAsyncFilesData;
while (jobExecutionResult.batchStatus === 'RUNNING' ||
jobExecutionResult.batchStatus === 'STARTING' &&
!errorDetected) {
console.log('@@@ jobExecutionResult=' + JSON.stringify(jobExecutionResult));
postMessageWithLog(jobExecutionResult);
console.log('Before sleep');
sleep(10000);
console.log('After sleep');
softLayerService.getAsyncFiles(jobExecutionResult.jobInstanceId, jobExecutionResult.jobExecutionId).subscribe(
(getAsyncFilesData: SpringBatchJobExecutionStatus) => {
jobExecutionResult = getAsyncFilesData;
postMessageWithLog(jobExecutionResult);
},
(error) => {
console.log('Error getting job execution status ' + error);
let errorBlock = new SpringBatchJobExecutionStatus();
errorBlock.httpRequestSuccessful = false;
postMessageWithLog(errorBlock);
errorDetected = true;
}
);
console.log('After end jobExecutionResult fetch loop');
} /* end while */
} else {
let errorBlock = postAsyncFilesData;
errorBlock.httpRequestSuccessful = false;
console.log('Not entering check loop batchStatus=' +
errorBlock.batchStatus +
' exitStatus=' + errorBlock.exitStatus);
postMessageWithLog(errorBlock);
}
},
(error) => {
let errorBlock = new SpringBatchJobExecutionStatus();
errorBlock.httpRequestSuccessful = false;
postMessageWithLog(errorBlock);
});
}
)();
console.log('@@@ addEventListener(...): worker ended');
});

请原谅console.log语句。一旦测试了关键的方面,它们中的大多数将被删除。

SoftlayerService类包含(最终)通过RXJS进行RESTful调用的方法

帮助:)

谢谢,樵夫

我通过添加tsconfig来解决这个问题。通过添加:"angularCompilerOptions" {"skipLibCheck"没错,"fullTemplateTypeCheck"没错,"strictInjectionParameters"没错}

我认为这是skipLibCheck: true,但不能确定。

最新更新