Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lodash/fp with ESM #5285

Closed
luiz290788 opened this issue Oct 20, 2021 · 11 comments
Closed

lodash/fp with ESM #5285

luiz290788 opened this issue Oct 20, 2021 · 11 comments
Labels
issue bankruptcy Closing the issue/PR to start fresh

Comments

@luiz290788
Copy link

Is there anyway to use ESM with lodash/fp? I tried lodash-es but it looks like fp functions are not published as part of that pacakge.

@dobernike
Copy link

Is there anyway to use ESM with lodash/fp? I tried lodash-es but it looks like fp functions are not published as part of that pacakge.

I only found a way to use it in an ESM package, like: import compose from 'lodash/fp/compose.js'.

@phhu
Copy link

phhu commented Jul 20, 2022

import fp from 'lodash/fp.js';
const {pipe, map, pickBy} = fp;

...seems to work.

@mohit-singh-pepper
Copy link

I don't think tree shaking will work like this.

@segevfiner
Copy link

Why...? Why wouldn't lodash-es also have the fp functions... Seriously... lodash CJS/ESM is a total mess. It should really be an hybrid CJS/ESM package under the same name with everything available (Using package.json entry points and exports)... This will make stuff just work so that bundlers can pick the ESM build and CJS only stuff can pick the CJS build.

@jdalton
Copy link
Member

jdalton commented Feb 26, 2023

It’s because lodash-fp is a wrapper around lodash which makes it difficult to modularize

@segevfiner
Copy link

Wouldn't it just require yet another specialized transformation in the lodash cli for it? Same way that lodash-fp itself is created?

@jdalton
Copy link
Member

jdalton commented Feb 26, 2023

I would require some tweaking and was technically possible with some back bending however, it’s been like 8yrs now so can say this confidently, FP in JavaScript is an anti pattern for work in teams and anything perf critical. I’m okay not investing in it going forward.

@segevfiner
Copy link

What would you suggest for use as an alternative to chain when you want to tree shake lodash?

@dword-design
Copy link

dword-design commented Feb 26, 2023

To jump into this discussion, I use the Babel pipeline operator and current proposal relies on non-FP functions. So stuff like this should work:

const foo = obj
  |> groupBy(%, 'name')
  |> mapValues(%, 'foo')

Drawback is that it isn't currently supported by TypeScript and that the proposal doesn't proceed a lot. Still I think that chained function calls without pipe doesn't scale.

@jdalton jdalton added the issue bankruptcy Closing the issue/PR to start fresh label Sep 16, 2023
@jdalton jdalton closed this as completed Sep 16, 2023
stefreak added a commit to garden-io/garden that referenced this issue Oct 16, 2023
Chain and tree-shaking (happens during bundling in rollup) do not work
well together.

Unfortunately we cannot use flow for all functions as we cannot import
lodash/fp functions with lodash-es, see also: lodash/lodash#5285
@haskelcurry
Copy link

Is there any chance of reviving this topic? Lodash/FP is absolutely needed, ESM is needed too

@morewings
Copy link

Is there any chance of reviving this topic? Lodash/FP is absolutely needed, ESM is needed too

Just use Ramda 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue bankruptcy Closing the issue/PR to start fresh
Development

No branches or pull requests

9 participants