Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

why we need to use

import groupBy from 'lodash.groupby'  
import isNil from 'lodash.isnil'

instead of below?

import {groupBy,isNil} from 'lodash'

is this still needed?

There are a bunch of different approaches and results and most of the are for 2020, 2019 or older.
What is the rightway? can we use a syntax like this

import {groupBy,isNil} from 'lodash' or 'lodash-es'

And what is the difference between the lodashandlodash-es`?
It would greatly appreciated it if anyone shed some light on this topic.

You must be logged in to vote

For modern environments you should import from lodash-es.

import { groupBy } from 'lodash-es'

Replies: 1 comment · 4 replies

Comment options

For modern environments you should import from lodash-es.

import { groupBy } from 'lodash-es'
You must be logged in to vote
4 replies
@seyyedhassanpour
Comment options

Thank you for your response. It would be greatly appreciated if you answer this one:
With this pattern, all the package wont be included into final bundle?

@ZachHaber
Comment options

Assuming that none of your other dependencies rely on the base 'lodash' package, that's correct. If they do, however, you will likely get double lodash included.

@hellohejinyu
Comment options

Assuming that none of your other dependencies rely on the base 'lodash' package, that's correct. If they do, however, you will likely get double lodash included.

import groupBy from 'lodash/groupBy'

What will happen if I use it like this?🧐

@ZachHaber
Comment options

What will happen if I use it like this?🧐

Then you'll get double groupBy if you have the full lodash imported anywhere already... Triple if you also have lodash-es, and quadruple if you also have lodash.groupBy... etc... 😢

There are so many different way to accidentally end up with multiple lodash packages installed.

Answer selected by jdalton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.