FileSaver.js icon indicating copy to clipboard operation
FileSaver.js copied to clipboard

export 'saveAs' was not found in 'file-saver'

Open gillesfabre34 opened this issue 6 years ago • 18 comments

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

gillesfabre34 avatar Sep 27 '18 15:09 gillesfabre34

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.

buu700 avatar Sep 27 '18 17:09 buu700

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

jimmywarting avatar Sep 27 '18 18:09 jimmywarting

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

jimmywarting avatar Sep 27 '18 18:09 jimmywarting

@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?

jakegt1 avatar Sep 28 '18 08:09 jakegt1

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

jimmywarting avatar Sep 28 '18 09:09 jimmywarting

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.

jakegt1 avatar Sep 28 '18 10:09 jakegt1

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?

jakegt1 avatar Sep 28 '18 10:09 jakegt1

Hi,

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

import saveAs from 'file-saver';

gillesfabre34 avatar Sep 28 '18 14:09 gillesfabre34

I guess this issue can be closed now.

barrymichaeldoyle avatar Oct 15 '18 13:10 barrymichaeldoyle

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

jakegt1 avatar Oct 15 '18 14:10 jakegt1

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

elf-pavlik avatar Nov 08 '18 20:11 elf-pavlik

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

arcteezy avatar Dec 17 '18 05:12 arcteezy

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

viss3595 avatar May 21 '19 10:05 viss3595

How can i do download with specific path?

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

jimmywarting avatar May 21 '19 11:05 jimmywarting

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

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

komasoftware avatar Jun 30 '19 18:06 komasoftware

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

diesel167 avatar Aug 07 '19 09:08 diesel167

Using 'npm install file-saver --save' instead of 'npm install @types/file-saver --save' solved my problem,you can try it

zcq18962285918 avatar Jul 21 '22 07:07 zcq18962285918

I used "const { saveAs } = require('file-saver');" instead of "import" and it worked (reactjs+nextjs)

duongtriny avatar Mar 06 '24 09:03 duongtriny