ref(build): Relocate vendored deps out of node_modules in npm builds#21503
ref(build): Relocate vendored deps out of node_modules in npm builds#21503mydea wants to merge 1 commit into
node_modules in npm builds#21503Conversation
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| "paths": { | ||
| "@sentry/conventions/attributes": ["../../node_modules/@sentry/conventions/dist/attributes"] | ||
| } |
There was a problem hiding this comment.
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.
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) <noreply@anthropic.com>
625467a to
2a83a9f
Compare
|
Superseded: per discussion we're making |

Summary
Foundational build-infra change for the
@sentry/conventionsmigration. The per-package@sentry/conventionsPRs depend on this and it should merge first.Root cause
With
preserveModules: true, Rollup emits bundled dependencies that resolve fromnode_modules(e.g. the vendored@sentry/conventionsdevDependency) into an output directory literally namednode_modules(build/esm/node_modules/@sentry/conventions/dist/attributes.js).Node treats
node_modulesas 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.jsfiles there as CommonJS, so named imports fail:The same boundary also makes Vitest externalize the
/node_modules/path andrequire()it, which additionally fails on Node 18 (norequire(esm)support).Fix
A
relocate-vendored-modulesrollup-utils plugin moves bundlednode_modulesdeps to a plain_external/directory (kept undersrcsopreserveModulesroots it at the build root). Rollup rewrites every import specifier to the new location automatically, so thetype:modulescope 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/rrwebbundle in replay) are relocated as a unit.Also maps the
@sentry/conventions/attributessubpath inpackages/typescript/tsconfig.jsonfor the repo'snodemoduleResolution type builds.Verified with a full
yarn build:dev(all 45 projects) and by confirming a packed@sentry/react-routerresolves the relocated file as ESM.Ref: #20982
🤖 Generated with Claude Code