developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
7.99k stars 361 forks source link

Cannot build when importing @sentry/browser #1068

Closed danawoodman closed 7 months ago

danawoodman commented 7 months ago

When using microbundle to build a TypeScript project with @sentry/browser I get the following errors repeatedly until everything fails:

Circular dependency: node_modules/@sentry/browser/esm/sdk.js -> node_modules/@sentry/browser/esm/integrations/breadcrumbs.js -> node_modules/@sentry/browser/esm/sdk.js

All you have to do to reproduce is install and import @sentry/browser

Reproduction here

rschristian commented 7 months ago

Is that an error, or a warning? Unless I'm misremembering, Rollup only emits that as a warning, it shouldn't stop builds.

Edit: Looks like the builds complete without error. Keep in mind you're inlining @sentry/browser (not sure if you intend to or not) which is massive -- trying to do that in CodeSandbox might cause problems if you're seeing some.

danawoodman commented 7 months ago

Yeah, I realized that this was a false positive and there was some other hidden issue that was causing the build to fail, so it was just a warning.

The docs state to use Sentry browser exactly like this: https://github.com/getsentry/sentry-javascript/tree/master/packages/browser

Thanks for having a look!

rschristian commented 7 months ago

The JS usage was fine, I was just asking if you meant to inline the dep.

Microbundle, by default, will inline all devDependencies into your bundle -- for @sentry/browser, this is merging 65kb+ into your library, which is pretty sizable. Seems like something you'd want at the page level, not inlined into your library.

danawoodman commented 7 months ago

ah gotcha, no that's not what I would want to do. why does it inline devDeps?

rschristian commented 7 months ago

Because no other behavior really makes sense there.

If you're consuming lib A, but it isn't listed as a dependency (so NPM, CDNs, etc. won't pull it when users download/install your lib), how would it become available?

peerDeps signals the consumer should have it, deps signals the consumer will need to pull it, using devDeps therefore signals it needs to be included for the consumer.

Edit: Just to clarify, it of course only inlines devDeps you're actually consuming in your lib code. Prettier, etc. won't end up in your bundle or anything.