File saver is deprecated. How to resolve this issue from SonarQube

2.1k views Asked by At

Working on filesaver, while running SONAR QUBE it shows " 'fileSaver' is deprecated. use { autoBom: false } as the third argument "

 this.http.get(`getTemplate/${doc.id}`, { responseType: 'blob' }).subscribe(
      (data: any) => {
        fileSaver.saveAs(new Blob([data], { type: this.fileType }), doc.docName)

error :- 'fileSaver' is deprecated. use { autoBom: false } as the third argument

Even if I use autobom:false it still shows the same

Here is the code for autobom

this.http.get(`getDocument/${doc.docId}`, { responseType: 'blob' }).subscribe(
      (data: any) => {
        var blob = new Blob([data], { type: this.fileType });
        fileSaver.saveAs(blob, doc.docName,false);

'saveAs' is deprecated. use { autoBom: false } as the third argumentWhy is this an issue?

'fileSaver' is deprecated. use { autoBom: false } as the third argument Why is this an issue?

2

There are 2 answers

2
Joop Eggen On

It should be the setting of autoBom, not just false:

fileSaver.saveAs(blob, doc.docName, { autoBom: false });

See comment from @leokom.

1
jhonnyfc On

I had the same issue. I fixed by importing only the function.

For ts

import { saveAs } from 'file-saver';

saveAs(blob, doc.docName);

For js

const { saveAs } = require('file-saver');

I think that this sonar issue is because the browsers do not natively support interface.