0

I need help.I am trying to decompress a zip file with angular using extract-zip.

but I got the following error :

./node_modules/extract-zip/index.js:9:4-17 - Error: Module not found: Error: Can't resolve 'fs' in 'D:\TONWEYA\ig-recovery\node_modules\extract-zip '

./node_modules/fd-slicer/index.js:1:9-22 - Error: Module not found: Error: Can't resolve 'fs' in 'D:\TONWEYA\ig-recovery\node_modules\fd-slicer'

./node_modules/yauzl/index.js:1:9-22 - Error: Module not found: Error: Can't resolve 'fs' in 'D:\TONWEYA\ig-recovery\node_modules\yauzl'

./node_modules/zlib/lib/zlib.js:1:0-43 - Error: Module not found: Error: Can't resolve './zlib_bindings' in 'D:\TONWEYA\ig-recovery\node_modules\zl ib\lib'

this is my code :

import extractZip from 'extract-zip';


async onFileSelected(event: any): Promise<void> {
   this.fichier = event.target.files[0];

   extractZip("D:\\TONWEYA\\unzip\\demo.zip", {dir: "D:\\TONWEYA\\unzip"});

 }

I am really wait for your help. I'm using angular 13.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158

1 Answers1

0

The problem is related to the fact that extract-zip package uses node native imports, see this issue.

In order to fix it you need to extend your app's configuration, so you can use them in browser. Take a look at the solution provided in this answer

In your case your config should look like:

"browser": {
    ...,
    "fs": false
}

Update: Also take a look at this discussion, you may notice other possible solutions for your case. Another option is to use a different library like jszip. This library does not use native imports.

AntGrisha
  • 409
  • 1
  • 3
  • 13
  • I tried all of these things. but it doesn't work. please , if you have a code that work, send it to me. Im using angular 13. – markoye Feb 18 '22 at 23:05