Skip to content

ref(build): Relocate vendored deps out of node_modules in npm builds#21503

Open
mydea wants to merge 1 commit into
developfrom
feat/use-sentry-conventions-build-infra
Open

ref(build): Relocate vendored deps out of node_modules in npm builds#21503
mydea wants to merge 1 commit into
developfrom
feat/use-sentry-conventions-build-infra

Conversation

@mydea

@mydea mydea commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

Foundational build-infra change for the @sentry/conventions migration. The per-package @sentry/conventions PRs depend on this and it should merge first.

Root cause

With preserveModules: true, Rollup emits bundled dependencies that resolve from node_modules (e.g. the vendored @sentry/conventions devDependency) into an output directory literally named node_modules (build/esm/node_modules/@sentry/conventions/dist/attributes.js).

Node treats node_modules as a package-scope boundary: the {"type":"module"} marker we emit at the ESM build root does not apply inside it. Node then loads our ESM .js files there as CommonJS, so named imports fail:

Named export 'HTTP_TARGET' not found. The requested module '.../node_modules/@sentry/conventions/dist/attributes.js'
is a CommonJS module, which may not support all module.exports as named exports.

The same boundary also makes Vitest externalize the /node_modules/ path and require() it, which additionally fails on Node 18 (no require(esm) support).

Fix

A relocate-vendored-modules rollup-utils plugin moves bundled node_modules deps to a plain _external/ directory (kept under src so preserveModules roots it at the build root). Rollup rewrites every import specifier to the new location automatically, so the type:module scope marker applies and neither the Node ESM/CJS heuristic nor Vitest's externalization fire. Modules with internal relative imports (e.g. the multi-file @sentry/rrweb bundle in replay) are relocated as a unit.

Also maps the @sentry/conventions/attributes subpath in packages/typescript/tsconfig.json for the repo's node moduleResolution type builds.

Verified with a full yarn build:dev (all 45 projects) and by confirming a packed @sentry/react-router resolves the relocated file as ESM.

Ref: #20982

🤖 Generated with Claude Code

mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mydea added a commit that referenced this pull request Jun 12, 2026
Source span/attribute keys from `@sentry/conventions` instead of the previous
OpenTelemetry / vendored convention constants. No functional change.

Depends on #21503 (relocates vendored deps out of `node_modules` in the build).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 625467a. Configure here.

Comment thread dev-packages/rollup-utils/plugins/npmPlugins.mjs
Comment on lines +22 to +24
"paths": {
"@sentry/conventions/attributes": ["../../node_modules/@sentry/conventions/dist/attributes"]
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is actually related to follow up PRs but is foundational enough that we may as well also do it here I suppose... this is for the node bundler strategy to be able to resolve the subpath import properly for types.

@mydea mydea marked this pull request as ready for review June 12, 2026 11:28
@mydea mydea requested review from andreiborza and nicohrubec June 12, 2026 11:28
With `preserveModules: true`, Rollup emits bundled dependencies that resolve from
`node_modules` (e.g. a vendored devDependency like `@sentry/conventions`) into an
output directory literally named `node_modules`. Node treats `node_modules` as a
package-scope boundary, so the `{"type":"module"}` marker we emit at the ESM build
root does NOT apply inside it — Node then loads our ESM `.js` files there as CommonJS
(named imports fail with "is a CommonJS module"), and Vitest externalizes any
`/node_modules/` path and `require()`s it, which additionally breaks on Node 18.

This adds a rollup-utils plugin that relocates such modules to a plain `_external/`
directory (Rollup rewrites the import specifiers automatically), so the scope marker
applies and the heuristics no longer fire. Also maps the `@sentry/conventions/attributes`
subpath in the shared TS config for `node` moduleResolution type builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mydea mydea force-pushed the feat/use-sentry-conventions-build-infra branch from 625467a to 2a83a9f Compare June 12, 2026 11:33
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.

1 participant