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

feat(module): export saveAs method and define module entrypoint

Open cristinecula opened this issue 5 years ago • 21 comments

Fixes https://github.com/eligrey/FileSaver.js/issues/538

This enables code using es modules to do:

import {saveAs} from 'file-saver'

Legacy js code is not affected by this change.

cristinecula avatar Oct 16 '19 16:10 cristinecula

So, I don't think this PR will be accepted because you're manipulating a dist output coming from babel transform. The underlying problem here is that the babel transform to UMD is messed up with respect to exports. This is discussed here: https://github.com/babel/babel/issues/10696.

You probably need to put pressure on the babel group to fix their library.

chrisknoll avatar Jun 11 '20 21:06 chrisknoll

@chrisknoll the updated dist output is generated by babel, I did not edit it by hand (I might be wrong though... this PR is very old).

cristinecula avatar Jun 12 '20 05:06 cristinecula

Understood, Thanks. I see it now, your addition of 'export saveAs' probably led to the change.

chrisknoll avatar Jun 12 '20 07:06 chrisknoll

Angular 10 is putting pressure on moving from Common JS to ES modules, could we for example put this pr as separate version of filesaver.js just like with lodash-es?

kbrilla avatar Jun 29 '20 08:06 kbrilla

Why this is not yet merged in? It is really helpful feature.

fidlip avatar Sep 10 '20 09:09 fidlip

Why this is not yet merged in? It is really helpful feature.

+1

Migrating from Angular 8 to Angular 10.

agarciacalvo avatar Sep 10 '20 14:09 agarciacalvo

Is there any intension for this to be merged, or even for the creation of a seperate version as mentioned by @criskrzysiu

ammaarpatel99 avatar Sep 15 '20 09:09 ammaarpatel99

Any update? Would be cool to eliminate the warning: CommonJS or AMD dependencies can cause optimization bailouts.

woteska avatar Oct 05 '20 10:10 woteska

It's causing fail in my app, any updates?

PredragCrnogorac avatar Oct 19 '20 07:10 PredragCrnogorac

Is this something that we just need to rely on a fork to resolve? Unfortunate, but what else can be done?

chrisknoll avatar Oct 19 '20 11:10 chrisknoll

Any update? I have the same warning: CommonJS or AMD dependencies can cause optimization bailouts.

grungert avatar Nov 03 '20 13:11 grungert

@cristinecula thanks for doing the legwork on this. Hopefully it gets merged soon.

In the meantime, I thought I'd share an easy way to install this PR in your node modules folder for us script kiddies out there:

npm i git+ssh://[email protected]/plumelo/FileSaver.js.git#master

then it should be easy to replace once this package gets updated.

[edit] linked the wrong package. sorry!

swordensen avatar Nov 05 '20 19:11 swordensen

Our dependencies are loaded via package.json. Can I specify that information in the package dependencies? Making all our consumers of our library run that command manually for their local installs is not feasible.

chrisknoll avatar Nov 05 '20 22:11 chrisknoll

Our dependencies are loaded via package.json. Can I specify that information in the package dependencies? Making all our consumers of our library run that command manually for their local installs is not feasible.

Sorry about that, I @'d the wrong person. To answer your question that line should add the fork to your package.json dependencies. But, if you have any more questions regarding installing packages from github I highly suggest using stack overflow so this thread can remain on topic :)

swordensen avatar Nov 05 '20 22:11 swordensen

In all fairness, you brought it up....

chrisknoll avatar Nov 06 '20 00:11 chrisknoll

I stumbled across https://www.npmjs.com/package/file-saver-es which seems to address this issue.

Not sure how "official" this package is however.

yglodt avatar Jan 26 '21 15:01 yglodt

@eligrey As the sole owner of this repo, can you have a look at this PR. It will help the whole Angular community if this gets merged.

jerone avatar Oct 21 '22 09:10 jerone

@eligrey Since you approved the PR, could you merge and publish a new version ? It has been 3 years since the PR has been opened and it's still an issue. I get this in Nuxt 3 when I generate for static hosting.

Named export 'saveAs' not found. The requested module 'file:///Users/sleblanc/Github/neobigben/node_modules/file-saver/dist/FileSaver.min.js' is a CommonJS module, which may not support all module.exports as named exports.

mrleblanc101 avatar Jan 01 '23 00:01 mrleblanc101

@eligrey @cristinecula could you give an update on this? Would be really cool if this PR lands soon in file-saver 👍🏽

colinscz avatar Mar 17 '23 08:03 colinscz

@cristinecula can you please resolve the branch conflicts?

acohenOT avatar Jul 24 '23 14:07 acohenOT

@eligrey is there any update on this?

it's been a while... :/

colinscz avatar Mar 22 '24 11:03 colinscz