question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

concurrently imports the entire date-fns library without tree-shaking but use only 1 function

See original GitHub issue

I have found this issue while investigating why my project still had the entire date-fns library bundled even if I was carefully importing and using only a few functions.

date-fns provides a syntax that will allow bundlers like Webpack to do some “tree-shaking” and only import the needed modules rather than the full library, optimizing greatly the total bundle size.

It seems like concurrently doesn’t use this syntax, which causes to import the full date-fns library instead of only the single function used in logging (formatDate in logger.ts and log-timings.ts).

How found this :

I had opened an issue about this originally on the date-fns repo because I thought it came from there.

After some discussions around the issue, someone mentioned here that it could come from another dependency importing all of date-fns by not using tree-shaking syntax. The recommendation was to use npm why date-fns to spot which other dependency may use date-fns.

When running that command, it only listed my own references to date-fns (using the syntax allowing tree-shaking) and the concurrently library.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
guillaumeprevostcommented, Jul 12, 2022

Hi, yes that’s fair enough… I did not have any free time to work on a minimal reproduction of this issue. Thank you

2reactions
paescujcommented, Jul 11, 2022

Closing this as I don’t see any room for improvement here on our side. Please open a new issue with a reproduction if this is still a problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree shaking issue in v2.28 #3004 - date-fns/date-fns - GitHub
I use only a few of the functions and made sure I import them as ... concurrently imports the entire date-fns library without...
Read more >
date-fns - modern JavaScript date utility library
date -fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >
date-fns 2 - can't get tree-shaking to work - Stack Overflow
Every time you import something from date-fns it will look up the import using the alias, avoiding the full import of the entire...
Read more >
The moment.js ultimate lightweight alternative: date-fns
You import whatever functions you want and use them with the Date objects. ... It means no tree-shake, and we cannot use js...
Read more >
Slim down your webpack bundle: Effectively reducing loading ...
Enable tree-shaking by using the new es modules import syntax. While webpack -p is one of the fastest ways to reduce the payload....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found