Filesaver.js: export 'saveAs' was not found in 'file-saver'

Created on 27 Sep 2018  路  16Comments  路  Source: eligrey/FileSaver.js

Hello,

I have the message error "export 'saveAs' was not found in 'file-saver'"
That's strange, beacause I have
"file-saver": "^2.0.0-rc.2",
in my package.json,
and I have too the directory "file-saver" in my node_modules folder.
So I don't understand why I have this error message.

public download(fileName: string) {
    fileName = 'learning-dataFR.txt';
    console.log('%c upload fileName : ', 'color: blue; font-weight: bold;', fileName);
    this.httpClient.get(environment.apiUrl + '/learning/download/' + fileName, { headers: this.httpHeaders, responseType: 'blob' })
      .subscribe(blob => {
        console.log('%c upload blob : ', 'color: blue; font-weight: bold;', blob);
        this.saveFile(blob, 'zzz.txt');
      });
  }
  public saveFile(blobContent: Blob, fileName: string)  {
    console.log('%c upload blobContent : ', 'color: green; font-weight: bold;', blobContent);
    const blob = new Blob([blobContent], { type: 'application/octet-stream' });
    console.log('%c upload fileName : ', 'color: green; font-weight: bold;', fileName);
    saveAs(blob, fileName);
  }

Thanks for your help

Most helpful comment

import saveAs from 'file-saver' is not work. import {saveAs} from 'file-saver'; not work too(
I get "Uncaught SyntaxError: Unexpected identifier "

All 16 comments

Not sure what changed or why this is now necessary, but I resolved this my changing my import to import fileSaver from 'file-saver'; and using fileSaver.saveAs.

import export module.exports is hard to get right. how can it be so difficult?

damm it i'm switching back to moduie.export = saveAs
screw export syntax
module.exports seems to solve most stuff

@jimmywarting i now cannot import this with normal ES6 module imports, i do only use this in dev but it's quite frustrating for now - would you be able to look into making this work with everything?

I don't know how to make it work for everything

it's ok, i understand and it's not really your fault, it's more just a problem with how much the JS ecosystem sucks in general. Thanks for trying anyway.

For the libraries i use commonly, moment seems to have it working for everything so maybe it's worth looking into see what they do?

Hi,

and thanks all for your help.
I fixed this bug with this import, without any { } :

import saveAs from 'file-saver';

I guess this issue can be closed now.

I'd probably keep it open until it works on everything, or remade with a better header.

Maybe src would have simple ES6 module which browser can import directly. Also most if not all modern bundles can handle ES6 imports. dist could just have a build which attaches saveAs to window

You have to include types. npm install @types/file-saver --save

How can i do download with specific path?
Like "C:\example.zip"

How can i do download with specific path?

@viss3595 you can't. you need to change your browser settings for that

You have to include types. npm install @types/file-saver --save

and from there ? how to import and use as ES6 module ?

import saveAs from 'file-saver' is not work. import {saveAs} from 'file-saver'; not work too(
I get "Uncaught SyntaxError: Unexpected identifier "

Was this page helpful?
0 / 5 - 0 ratings