eligrey / FileSaver.js

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

Load with Polymer 3 / ES6 #607

Open derhuebiii opened 4 years ago

derhuebiii commented 4 years ago

Hi,

I want to use FileSaver in a Polymer 3 project.

I think I tried all possible combinations of:

import saveAs from '../node_modules/file-saver/dist/FileSaver.js';
import fileSaver from '../node_modules/file-saver/dist/FileSaver.js';
import * as fileSaver from '../node_modules/file-saver/dist/FileSaver.js';
import '../node_modules/file-saver/dist/FileSaver.js';
...

with { } and without etc...none of them seem to work.

Any suggestions? Thanks! :)

NicolasCARPi commented 4 years ago
import { saveAs } from 'file-saver/dist/FileSaver.js';

works for me with typescript/es6.

Note that you can also install/add @types/file-saver ;)

LennyKiano commented 3 years ago

@derhuebiii I am also using a polymer 3.0 set up and this is how I resolved the issue

  1. For the import, point directly to the module js file eg :

import { saveAs } from '../../../node_modules/file-saver/FileSaver';

  1. Go to the FileSaver.js in the node_module directory and add export in front of : var saveAs = saveAs

This worked for me