Skip to content

chore: Use the isolated pnpm node_modules layout - #25368

Open
JPeer264 wants to merge 6 commits into
jp/node-modules-pnpm-isolatedfrom
jp/pnpm-isolated
Open

JPeer264 wants to merge 6 commits into
jp/node-modules-pnpm-isolatedfrom
jp/pnpm-isolated

Conversation

@JPeer264

@JPeer264 JPeer264 commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

This moves the monorepo from the hoisted node_modules layout to the isolated pnpm default. Each package now declares the packages that it imports, instead of using what the root folder had. A full build gives the same files as with the hoisted layout.

  • Packages declare the dependencies that they imported from the hoisted root folder, with the version that the root folder had. The lockfile gets no new versions.
  • The root package.json no longer lists every workspace package as workspace:*. Each package declares the workspace packages that it imports, for example @sentry-internal/rollup-utils in the rollup configs. The root keeps three of them: @sentry-internal/node-integration-tests (its suites import it by name, also from tmp folders with their own package.json), @sentry/eslint-plugin-sdk (oxlint plugin) and @sentry/sveltekit (size-limit bundles its self-import).
  • @sentry/replay declares @sentry/conventions as a dev dependency, so its build still inlines the constant from there.
  • rollup-utils reads the sideEffects field of external packages from the nearest node_modules of the built package, not only from the root folder.
  • The integration test runner adds the bins of node-integration-tests to the PATH of setup commands (for example prisma generate), because the Bun and Deno packages run the shared suites with their own PATH.
  • The install-playwright action runs npx playwright outside the repository. In the repository, npm finds that version in node_modules/.pnpm and then looks for node_modules/.bin/playwright, which the root folder no longer has.

SDK fix

modulesIntegration did not find the versions of CJS modules in the isolated pnpm layout (node_modules/.pnpm/<id>/node_modules/<name>), so pnpm apps got the version ranges of their package.json instead. It now reads these folders too. The suites/modules CJS test covers it, because it now runs on this layout.

packageExtensions decisions

@apm-js-collab/code-transformer-bundler-plugins imports the types of Vite, Rollup, webpack and esbuild without declaring them. pnpm-workspace.yaml declares them as optional peers, so its types use the Vite of the importing package. The real fix belongs upstream.

Peer decisions

autoInstallPeers stays false. The pnpm default (true) adds 674 package versions for peers that no package needs, for example @glimmer/component and the GraphQL tools of Gatsby.

Known issues

  • Size Check shows about 4 KB more for the unminified @sentry/cloudflare (withSentry) entry, but it stays under the 516 KiB limit of develop. Some other entries change by up to 200 bytes. The bundled code is the same, but the bundles contain the longer node_modules/.pnpm/... file paths.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.88 kB - -
@sentry/browser - with treeshaking flags 28.02 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.92 kB - -
@sentry/browser (incl. Tracing) 52.07 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.07 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.02 kB - -
@sentry/browser (incl. Tracing, Replay) 91.82 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.68 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.55 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.49 kB - -
@sentry/browser (incl. Feedback) 47.4 kB - -
@sentry/browser (incl. sendFeedback) 34.94 kB - -
@sentry/browser (incl. FeedbackAsync) 40.05 kB - -
@sentry/browser (incl. Metrics) 30.9 kB - -
@sentry/browser (incl. Logs) 31.18 kB - -
@sentry/browser (incl. Metrics & Logs) 31.81 kB - -
@sentry/react 31.7 kB +0.01% +1 B 🔺
@sentry/react (incl. Tracing) 54.39 kB +0.01% +2 B 🔺
@sentry/vue 38.04 kB - -
@sentry/vue (incl. Tracing) 55.01 kB - -
@sentry/svelte 29.9 kB - -
@sentry/remix (Remix 3 client bundle) 57.08 kB - -
CDN Bundle 31.64 kB - -
CDN Bundle (incl. Tracing) 52.58 kB - -
CDN Bundle (incl. Logs, Metrics) 33.84 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.52 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.77 kB - -
CDN Bundle (incl. Tracing, Replay) 90.25 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.18 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.34 kB - -
CDN Bundle - uncompressed 93.18 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 161.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.76 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.2 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.9 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.84 kB - -
@sentry/nextjs (client) 56.84 kB +0.01% +1 B 🔺
@sentry/sveltekit (client) 52.45 kB - -
@sentry/core/server 41.12 kB - -
@sentry/core/browser 13.81 kB - -
@sentry/node 155.04 kB +0.01% +9 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 84.06 kB - -
@sentry/node - without tracing 96.7 kB +0.01% +4 B 🔺
@sentry/node - without channel injection 133.07 kB +0.01% +5 B 🔺
@sentry/aws-serverless 104.89 kB +0.01% +4 B 🔺
@sentry/cloudflare (withSentry) - minified 210.78 kB - -
@sentry/cloudflare (withSentry) 526.86 kB +0.76% +3.96 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 228.46 kB - -

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/pnpm-isolated branch 2 times, most recently from 755fc00 to 00d9d69 Compare October 14, 2026 20:33
@JPeer264
JPeer264 added this pull request to stack #25387 October 15, 2026 08:47
@JPeer264
JPeer264 force-pushed the jp/pnpm-isolated branch 2 times, most recently from f1386d1 to 5c6dd85 Compare October 15, 2026 11:20
@JPeer264
JPeer264 force-pushed the jp/pnpm-isolated branch 2 times, most recently from 3ab242c to 621c3a3 Compare October 15, 2026 14:57
Base automatically changed from jp/move-to-pnpm to develop October 19, 2026 06:56
@JPeer264
JPeer264 force-pushed the jp/pnpm-isolated branch 2 times, most recently from ee68feb to 94240b6 Compare October 19, 2026 10:06
@JPeer264
JPeer264 marked this pull request as ready for review October 19, 2026 10:59
@JPeer264
JPeer264 requested review from a team as code owners October 19, 2026 10:59
@JPeer264
JPeer264 requested review from andreiborza, chargome, isaacs, logaretm, mydea and s1gr1d and removed request for a team, chargome, logaretm and mydea October 19, 2026 10:59
Comment thread packages/node/src/integrations/modules.ts
Comment thread package.json Outdated
@JPeer264
JPeer264 removed this pull request from stack #25387 October 19, 2026 13:42
@JPeer264
JPeer264 changed the base branch from develop to jp/node-modules-pnpm-isolated October 19, 2026 13:44
@JPeer264
JPeer264 added this pull request to stack #25528 October 19, 2026 13:44
JPeer264 and others added 6 commits October 19, 2026 16:58
The test runs a webpack production build. On the Node 20 CI runners it
takes 3 to 5 seconds, close to the 5 second default timeout, and some
runs time out. Locally it takes about 0.3 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove `nodeLinker: hoisted` and `shamefullyHoist`, so pnpm installs its
default isolated layout. Each package now resolves only the dependencies
that it or the root package.json declares.

- Packages declare the dependencies that they imported from the hoisted
  root folder, with the version that the root folder had. The lockfile
  gets no new versions.
- `tslib` is a root devDependency, because the shared tsconfig sets
  `importHelpers`.
- @sentry/replay declares `@sentry/conventions` as a devDependency, so
  its build still inlines the constant that it imports from there.
- react-router, solidstart, sveltekit and tanstackstart-react declare
  `@types/node` 18 like the root. Without it, the optional `@types/node`
  peer of Vite resolves to version 20, and the Vite plugin types of
  @sentry/server-utils do not match.
- `packageExtensions` declares the bundlers as optional peers of
  @apm-js-collab/code-transformer-bundler-plugins, because its type
  declarations import them.
- rollup-utils reads the `sideEffects` field of an external package from
  the nearest node_modules folder of the built package, not only from the
  root folder. Without this, the builds keep empty imports of packages
  that are not in the root folder, for example `import '@sentry/core'`.
- The integration test runner adds the bins of node-integration-tests
  to the `PATH` of setup commands such as `prisma generate`, because the
  Bun and Deno packages run the shared suites with their own `PATH`.
- The install-playwright action runs `npx playwright` outside the
  repository. In the repository, npm finds the playwright version in
  `node_modules/.pnpm` and then runs `node_modules/.bin/playwright`,
  which the root folder no longer has.
- The size limit of `@sentry/cloudflare (withSentry)` goes from 514 KiB
  to 515 KiB. This check bundles without minification, so the bundle
  keeps the module paths, which are about 4 KB longer under
  `node_modules/.pnpm`. The code in the bundle is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The root package.json listed every workspace package as a `workspace:*`
devDependency, so that each package could import any of them from the
root node_modules folder like with Yarn. Remove these entries and
declare the workspace packages in the packages that import them, for
example `@sentry-internal/rollup-utils` in the rollup configs.

The root keeps three of them:
- `@sentry-internal/node-integration-tests`, because its suites import
  it by its own name, also from tmp folders that have their own
  package.json.
- `@sentry/eslint-plugin-sdk`, because the root oxlint config loads it
  as a JS plugin.
- `@sentry/sveltekit`, because size-limit bundles its build output,
  which imports `@sentry/sveltekit/browser-tracing-variant`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JPeer264
JPeer264 requested a review from s1gr1d October 19, 2026 15:25

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits, but this mostly looks good to go.

},
"devDependencies": {
"premove": "^4.0.0",
"sentry": "^0.44.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking this should probably match the lockfile and @sentry/bundler-plugins deps, yeah?

Suggested change
"sentry": "^0.44.0",
"sentry": "^0.45.0",

"meriyah": "^6.1.4",
"vite": "^8.3.1"
"vite": "^8.3.1",
"webpack": "^5.0.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"webpack": "^5.0.0"
"webpack": "^5.104.1"

sideEffectFree = json.sideEffects === false;
} catch {
// Not resolvable from the repo root - assume side effects.
// Not resolvable from the built package - assume side effects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findPackageJson (down a few lines from here) walks from process.cwd() up to the repo root. If no node_modules/<name>/package.json exists, it returns the root candidate, readFileSync throws, and the package counts as having side effects.

The commit message says this exact fallback caused leftover import '@sentry/core' statements in builds before the fix. With the isolated layout, the fallback now happens whenever a package imports an external that it does not declare directly. The build still succeeds, but the output changes.

Suggestion: log a warning in the catch here, whenever the package is not a Node builtin. Then the next undeclared import shows up in the build log instead of in a later diff of the build output.

@@ -4,7 +4,7 @@ import { cp, mkdir, readFile, rm, writeFile } from 'fs/promises';
import { basename, join } from 'path';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { basename, join } from 'path';
import { basename, join, delimiter } from 'path';

// The Bun and Deno packages run these suites with their own `PATH`, which does not have the bins of
// this package (e.g. `prisma`).
const binPaths = [join(tmpDirPath, 'node_modules', '.bin'), join(PACKAGE_ROOT, 'node_modules', '.bin')];
const env = { ...process.env, PATH: `${binPaths.join(':')}:${process.env.PATH}` };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

':' is posix-only. Windows uses ';'. Import path.delimiter and use that instead.

Suggested change
const env = { ...process.env, PATH: `${binPaths.join(':')}:${process.env.PATH}` };
const env = { ...process.env, PATH: `${binPaths.join(delimiter)}:${process.env.PATH}` };

Comment thread pnpm-workspace.yaml

# Dependencies that import packages without declaring them. pnpm links these peers to the versions of the importer.
packageExtensions:
# Its type declarations import the bundler types.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says "the real fix belongs upstream".

Suggestion: open an issue on @apm-js-collab/code-transformer-bundler-plugins and link it in the YAML comment here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants