eligrey / FileSaver.js

An HTML5 saveAs() FileSaver implementation
https://eligrey.com/blog/saving-generated-files-on-the-client-side/
Other
21.65k stars 4.38k forks source link

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

Open gillesfabre34 opened 6 years ago

gillesfabre34 commented 6 years ago

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

buu700 commented 6 years ago

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.

jimmywarting commented 6 years ago

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

jimmywarting commented 6 years ago

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

jakegt1 commented 6 years ago

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

jimmywarting commented 6 years ago

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

jakegt1 commented 6 years ago

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 commented 6 years ago

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?

gillesfabre34 commented 6 years ago

Hi,

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

import saveAs from 'file-saver';

barrymichaeldoyle commented 6 years ago

I guess this issue can be closed now.

jakegt1 commented 6 years ago

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

elf-pavlik commented 6 years ago

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

arcteezy commented 5 years ago

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

viss3595 commented 5 years ago

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

jimmywarting commented 5 years ago

How can i do download with specific path?

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

komasoftware commented 5 years ago

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

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

diesel167 commented 5 years ago

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

zcq18962285918 commented 2 years ago

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

duongtriny commented 8 months ago

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