Error: Can't resolve 'worker_threads'
Robinyo opened this issue · 1 comments
Robinyo commented
I installed unzipit:
npm install unzipit@1.0.0
Added the following to a (Ionic / Angular) page:
import { setOptions, unzip } from 'unzipit';
setOptions({ useWorkers: false });
...
private async loadData() {
forkJoin([
this.documentService.getDocument(this.id, 'urn:oid:1.3.16.1.38818.449459763.20190718104352576')
]).subscribe(async data => {
const DOCUMENT = 0;
const decodedDocument = atob(data[DOCUMENT]);
const {entries} = await unzip(decodedDocument);
// print all entries and their sizes
for (const [name, entry] of Object.entries(entries)) {
console.log(name, entry.size);
}
});
}
Error:
[ng] Build at: 2022-07-10T00:43:16.263Z - Hash: dff3748d725239b3 - Time: 531ms
[ng]
[ng] ./node_modules/unzipit/dist/unzipit.module.js:1178:8-33 - Error: Module not found: Error: Can't resolve 'worker_threads' in '/Users/rob/workspace/adha/mobi/frontend/mobi/node_modules/unzipit/dist'
[ng]
[ng]
[ng] ✖ Failed to compile.
Environment:
ionic --version
6.20.1
Angular CLI: 13.2.6
Node: 18.2.0
Package Manager: npm 8.9.0
OS: darwin arm64
Angular: 13.2.7
... common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1302.6
@angular-devkit/build-angular 13.2.6
@angular-devkit/core 13.2.6
@angular-devkit/schematics 13.2.6
@angular/cli 13.2.6
@schematics/angular 13.2.6
rxjs 6.6.7
typescript 4.4.4
Robinyo commented
Ok, so I upgraded my Ionic / Angular project to "^14.0.0".
import { setOptions, unzip } from 'unzipit';
setOptions({ useWorkers: false });
And:
private async loadData() {
await LoadingService.presentLoading();
forkJoin([
this.documentService.getDocument(this.id, 'urn:oid:1.3.16.1.38818.449459763.20190718104352576')
]).subscribe(async data => {
const document = data[0];
const blob = base64toBlob(document, 'octet/stream');
const {entries} = await unzip(blob);
// print all entries and their sizes
for (const [name, entry] of Object.entries(entries)) {
this.logger.info(name, entry.size);
}
LoadingService.dismissLoading();
});
}
See: https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript
Console:
MockDocumentService: getDocument() - patientLogicalId: 979881974 documentId: urn:oid:1.3.16.1.38818.449459763.20190718104352576
document.page.ts:74 CDA/CDADoc/ 0
document.page.ts:74 CDA/CDADoc/CDA_ROOT.XML 95555
document.page.ts:74 CDA/CDADoc/CDA_SIGN.XML 4787