Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] Bundle monorepo dependencies in npm packages #5886

Closed
lobsterkatie opened this issue Oct 5, 2022 · 1 comment
Closed

[build] Bundle monorepo dependencies in npm packages #5886

lobsterkatie opened this issue Oct 5, 2022 · 1 comment

Comments

@lobsterkatie
Copy link
Member

lobsterkatie commented Oct 5, 2022

Problem Statement

In spite of the fact that - theoretically - updating one of our top-level packages (@sentry/browser, @sentry/node, and all framework-specific packages) should also update all monorepo dependencies (@sentry/utils, @sentry/core, etc), it's come up as a problem multiple times that this doesn't always happen. As a result, people end up with crashes when, for example, a newer version of @sentry/browser calls upon a recently-added hub method, an older version of @sentry/hub is still installed, and the user ends up with a undefined is not callable error.

This never comes up as a problem for people using our CDN bundle, because in that case all monorepo dependencies are included in the bundle.

Solution Brainstorm

To solve this, let's include our monorepo dependencies in our npm packages the same way we do in our bundles. We can still publish the dependencies as separate packages, for anyone who specifically needs them (people building community SDKs for frameworks we don't support, for example), but we'd stop listing them as runtime dependencies.


UPDATE: This is going to be trickier than I thought.

Leaving a note here for myself, of things I've tried which have not yet worked, for when I come back to this:
(tried with building nextjs SDK and bundling either utils or react packages)

  • move package to dev deps, don’t mark dev deps as external (adjust output for templates, loaders, adjust script to copy file to correct location)-> build/esm and build/cjs contain nextjs dir, dir for each non-external package, but doesn't work because other packages only contain esm, not cjs
  • symlink src folder from other package as nextjs/src/packages/ and change imports to point to that -> files from other package don't get included in build
  • symlink src/index.ts from other package into nextjs/src/packages/ and change imports to point to `./packages/ -> complains it can't find the module (not reading through symlink)
  • copy contents of other package src folder into nextjs/src/packages/ -> need to add all of other package's deps to nextjs package deps, turn on flags from other package builds (like jsx for react package)
  • copy correct files into build/esm and build/cjs folders, use output.paths rollup option to rewrite import to point to that folder -> replacement is hardcoded, so doesn't account for differences in relative path

Alternative option: Crate post-install script to verify versions of all deps, warn or error if out of sync (Not perfect - some people turn off scripts - but a lot better than nothing)

@AbhiPrasad
Copy link
Member

Going to close this as we are working toward it with profiling/replay/tracing inside the browser package directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants