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.

There seems to be something wrong with tree shaking

See original GitHub issue

When I import {useFocusTrap} from "@vueuse/integrations", all the lib is bundled (qrcode, buffer & co … ). repro npm install, npm run dev See stats.html in dist after build.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
antfucommented, Apr 21, 2021

Oh, that’s a good point and I didn’t notice that as I thought rollup will tree-shake unused modules. But looks like there is also no way to explicitly mark an import statement pure (https://github.com/rollup/rollup/issues/2874). The solution of this that comes up my mind is to separate functions into several sub-modules, e.g.

import {useFocusTrap} from "@vueuse/integrations/useFocusTrap"
import {useQRCode} from "@vueuse/integrations/useQRCode"

What do you think?

If we go that way, it will be a breaking change and I would like to do that in v5.

2reactions
milesingramscommented, Dec 13, 2021

When using the import { UseFocusTrap } from '@vueuse/integrations/useFocusTrap/component' in a Nuxt 3 project with @vueuse/integrations: 7.3.0 I’m getting the error:

SyntaxError: The requested module '/_nuxt/node_modules/qrcode/lib/browser.js?v=93c8fa7e' does not provide an export named 'default'

It appears that two things may be going on:

  1. Tree shaking is not happening and therefore the useQRCode composable is being loaded
  2. Somehow the useQRCode composable is possibly incorrectly importing qrcode

However this also may be an issue in Nuxt 3 and how it performs imports? Any help would be much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree-Shaking Problems with Component Libraries - Medium
Tree -shaking isn't magic, and much like the garbage collector, you need to understand a little of what it's doing to get the...
Read more >
Webpack5 does not seem to tree-shake unused exports
I tried changing all files to .js and removing the whole ts-loader thing. Tree-shaking now work as intented. The updated question now is...
Read more >
Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >
Tree-Shaking: A Reference Guide - Smashing Magazine
Tree -shaking” is a must-have performance optimization when bundling JavaScript. In this article, we dive deeper on how exactly it works and ...
Read more >
Component Library: Tree Shaking CSS solution - YouTube
A few days ago I presented a problem I was having with " Tree Shaking CSS" (watch it here: ...
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