Comments (5)
// bad // the entire package is imported import { v4 } from 'uuid'
The above is the correct syntax, and does in fact allow modern bundlers to "tree shake" out unused code. (See our examples
directory for examples of how this works with rollup and webpack.)
If this isn't working for you - i.e. if your bundles contain code for non-v4 versions - please provide a link to a functional example or repository demonstrating the problem and we can take a look. If there's it turns out to be a valid bug we can reopen this issue.
// good // only imports v4 and necessary dependencies import v4 from 'uuid/v4'
This is syntax won't work by design. We dropped support for deep imports a few major-versions back (v7... or maybe v8?)
from uuid.
If this isn't working for you - i.e. if your bundles contain code for non-v4 versions - please provide a link to a functional example or repository demonstrating the problem and we can take a look. If there's it turns out to be a valid bug we can reopen this issue.
Sure this my team's repo https://github.com/aws-observability/aws-rum-web
As shown below via webpack-bundle-analyzer
, we are including other modules such as md5, v1, v3 etc. despite our prod config https://github.com/aws-observability/aws-rum-web/blob/main/webpack/webpack.prod.js
![Screenshot 2024-06-19 at 1 39 57 PM](https://private-user-images.githubusercontent.com/43121212/341199976-cc4010e8-e977-4152-bd39-a5df8244e4cd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjExMDk4MzcsIm5iZiI6MTcyMTEwOTUzNywicGF0aCI6Ii80MzEyMTIxMi8zNDExOTk5NzYtY2M0MDEwZTgtZTk3Ny00MTUyLWJkMzktYTVkZjgyNDRlNGNkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE2VDA1NTg1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcxYTZjMWU5MzllMzMzODhiN2QxOTZiN2ZmOTNkNDczNjRhNWI3YjdlOWZjZTE2N2ZkOGVkMzQ1NzMyMTU3ODAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.9tJGybgTylng58adcS4-Qp98grTzA2rVhmA1vJ_QB7c)
How should this be done instead? Hopefully this is just a config error on our end
from uuid.
I've also reviewed https://webpack.js.org/guides/tree-shaking/#root and can't find any issues. We are using the production build, the default minimizer from TerserPlugin, and have marked zero side effects.
from uuid.
'Looks like the problem is that you're transpiling to commonjs, which bundlers aren't able to tree shake. While this project does provide commonjs builds, we don't provide the ability to deep import specific versions the way you're suggesting.
While I acknowledge that's a flaw in the existing API for CJS use cases, it's not something I'm interested in addressing at this time.
How should this be done instead?
Consider bundling for ESM. Failing that, I'd suggest switching from uuid
to [crypto.randomUUID()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)
, which is broadly supported now.
from uuid.
Thank you so much for the two strong callouts
- Compiling to commmon js is breaking our tree shaking
- Backup strategy to use native crypto package for uuids
from uuid.
Related Issues (20)
- NPM Deprication Message is ambiguous HOT 2
- Question: Do we still need it?
- Sponsored issue: Incremental UUID HOT 1
- [BUG] uncorrect validation uuid HOT 1
- [question] is posible decode uuid to data back ? HOT 1
- Add UUID type to use in TypeScript HOT 1
- validate method returns false for a valid UUID HOT 6
- Issue in the import statement HOT 1
- [BUG] Installing `uuid` has an inconsistent dependency chain causing build issues in ci/cd pipelines HOT 2
- uuidv6 has been officially adopted by the IETF HOT 3
- Tracking Issue: RFC 9562 / uuid@10 HOT 1
- Make `Uint8Array` the one and only type used for binary (byte) uuid values
- Drop support for `offset` argument, commit to `Uint8Array` type for binary uuids
- Add v8 Support HOT 1
- Port codebase to TypeScript HOT 1
- v7: passing `options.msecs` results in zero-value timestamp HOT 5
- Error: Cannot find module 'node:crypto' when I upgrade uuid version from 9.0.0. to 10.0.0 HOT 4
- [BUG] Module '"uuid"' has no exported member 'v7'.ts(2305) HOT 1
- feat: Add v6 and v7 to the command line utility HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uuid.