René's URL Explorer Experiment


Title: [v8] Update for ESM monkeypatch + ESM file structure · Issue #10046 · getsentry/sentry-javascript · GitHub

Open Graph Title: [v8] Update for ESM monkeypatch + ESM file structure · Issue #10046 · getsentry/sentry-javascript

X Title: [v8] Update for ESM monkeypatch + ESM file structure · Issue #10046 · getsentry/sentry-javascript

Description: We’re going to be adding proper support for ESM in the Sentry repo. Requirement: There is no require in ESM bundles at all ESM files have .mjs file extension CJS files have .cjs file extension ### Tasks - [ ] https://github.com/getsentry...

Open Graph Description: We’re going to be adding proper support for ESM in the Sentry repo. Requirement: There is no require in ESM bundles at all ESM files have .mjs file extension CJS files have .cjs file extension ### ...

X Description: We’re going to be adding proper support for ESM in the Sentry repo. Requirement: There is no require in ESM bundles at all ESM files have .mjs file extension CJS files have .cjs file extension ### ...

Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/10046

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[v8] Update for ESM monkeypatch + ESM file structure","articleBody":"We’re going to be adding proper support for ESM in the Sentry repo.\n\nRequirement:\n\n- There is no `require` in ESM bundles at all\n- ESM files have `.mjs` file extension\n- CJS files have `.cjs` file extension\n\n```[tasklist]\n### Tasks\n- [ ] https://github.com/getsentry/sentry-javascript/pull/10069\n- [x] (pre-v8) Figure out how to use `dynamicRequire` with ESM\n- [x] (pre-v8) Remove usage of `require.main.filename` for module name resolution #10061\n- [x] (v8) Vendor `https-proxy-agent` which is cjs only #10088\n- [x] (v8) Change build to output `mjs`/`cjs` for esm/cjs\n- [x] (v8) Remove conditional import of `worker_threads` #10791\n- [x] (v8) Update `inspector.d.ts` to work with esm and cjs\n- [x] (v8) Remove require call in `require('inspector')` in `LocalVariables` integration\n- [x] (v8) Update Rollup\n- [ ] https://github.com/getsentry/sentry-javascript/pull/10928\n- [ ] https://github.com/getsentry/sentry-javascript/issues/11066\n- [ ] https://github.com/getsentry/sentry-javascript/issues/11067\n```\n\nRead below for some justification and information\n\n## Module Customization Hooks for Monkey Patching\n\nFor ESM bundles on server-side, we’ll require a minimum Node version of `18.6.0` or `20.6.0` or higher. Otherwise we’ll support CJS bundles for Node 14+ generally. This is because we want access to [Node customization hooks](https://nodejs.org/api/module.html#customization-hooks), which allows us to add monkeypatching for esm modules programatically (doesn't require command-line `loader`).\n\nWe can take some inspiration here from https://github.com/DataDog/import-in-the-middle\n\n```js\nimport { register } from 'node:module';\n\nregister('./sentry-patch.mjs', import.meta.url);\n```\n\nRegistering hooks to affect an import still needs to happen before the import is resolved, so there are ordering issues, but I think we can work around this by recommending that `Sentry.init` is called as soon as possible, and encouraging `Sentry.addIntegration` patterns for integrations that require objects from different libraries (like express with `app`).\n\nThe modules we need register via `register` API:\n\n- ~Node `node:http` and `node:https` (diagnostics channels only works well Node 16+, so we need to maintain this for Node 14~\n- Remix `@remix-run/server-runtime` and ~`react-router-dom`~ - monkeypatch\n- OTEL esm instrumentation\n- `GoogleCloudGrpc` integration `require('google-gax')`\n- `GoogleCloudHttp` integration with `require('@google-cloud/common')`\n- `AWSServices` integration with `require('aws-sdk/global')`\n\n~We need to re-evaluate if we need monkeypatching for the database integrations now that we have OpenTelemetry.~\n\n## Change File Structure\n\nWe’ll need to move our file structure to the following:\n\n```js\n{\n  // at build time we strip `build/X`\n  \"main\": \"build/cjs/index.cjs\",\n  \"module\": \"build/esm/index.mjs\",\n  \"types\": \"build/types/index.d.cts\",\n  // note: this is an opportunity for us to explore multiple subpaths, like\n  // exporting from `@sentry/browser/utils`\n  \"exports\": {\n    \"./package.json\": \"./package.json\",\n    \".\": {\n      // esm\n      \"import\": {\n        // path must be relative\n        \"types\": \"./build/types/index.d.mts\",\n        \"default\": \"./build/esm/index.mjs\"\n      },\n      // cjs\n      \"require\": {\n        // path must be relative\n        \"types\": \"./build/types/index.d.cts\",\n        \"default\": \"./build/esm/index.mjs\"\n      }\n      // we might need to expose an ESM only export for customization hooks\n      // to use via node --loader=... API\n    }\n  },\n  \"typesVersions\": {\n    \"\u003c4.9\": {\n      \"build/types/index.d.cts\": [\n        \"build/types-ts3.8/index.d.cts\"\n      ],\n      \"build/types/index.d.mts\": [\n        \"build/types-ts3.8/index.d.mts\"\n      ]\n    }\n  },\n  \"files\": [\n    \"cjs\",\n    \"esm\",\n    \"types\",\n    \"types-ts3.8\"\n  ]\n}\n```\n\nShameless promo: [Watch my talk](https://www.youtube.com/watch?v=fpTa6oZR0ms) if you want more details about this.\n\nWe also should change all node standard library imports to import from `node:X`.\n\n## Make `dynamicRequire`/`loadModule` work with ESM import\n\nThis exists to trick webpack, but we use it all over the codebase. We need to add an esm compatible way.\n\nOne thing we can do is introduce an async `dynamicRequire` that simulates `await import`, and then build time replace the functionality of `dynamicRequire` to use `import` or `require` under the hood?\n\n- `packages/node/src/integrations/anr/index.ts` - to conditionally import `worker_threads`. This is just because of Node 12 support, we’ll remove this import entirely\n- `packages/node/src/integrations/local-variables/local-variables-async.ts` - to conditionally import `node:inspector/promises`.\n- All of our database integrations - these are all going away\n- `packages/utils/src/time.ts` - this needs to be refactored entirely. We still want an isomorphic solution because we need date-time helpers that work across core/browser/node and all other packages, but what should happen is that we look for the `globalThis.performance` instead of relying on `perf_hooks`. This means that if the global performance API is not available we will fall back to plain `[Date.now](http://Date.now)` and similar helpers (basically only Node 14 for us). We also need to add a smarter timeOrigin calculation that reset’s itself to help alleviate issues with drifting monotonic clock. See https://github.com/open-telemetry/opentelemetry-js/issues/3279#issuecomment-1320064182\n\n","author":{"url":"https://github.com/AbhiPrasad","@type":"Person","name":"AbhiPrasad"},"datePublished":"2024-01-04T03:30:21Z","url":"https://github.com/getsentry/sentry-javascript/issues/10046"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cda5a4b9-e0eb-9af8-305a-559d2c2c3b0a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id917C:1EE375:6F6D76:9C69A9:6B042057
html-safe-nonce9a8dd6ab57cb81e56135ba99da9218d0e65e15bcc0746a1c9c76901a02b2965e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTdDOjFFRTM3NTo2RjZENzY6OUM2OUE5OjZCMDQyMDU3IiwidmlzaXRvcl9pZCI6Ijg4NDY1MTAxODQ4MDIyOTU4OTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5d13a062a76894fd02843fdc765be6a92d134e7fab135fd4827b0783a8b784a7
hovercard-subject-tagissue:2064936029
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/10046/issue_layout
twitter:imagehttps://opengraph.githubassets.com/55da47acb87d95c6b463592d3a4432d53aa055c136338efdbb63326d82a34298/getsentry/sentry-javascript/issues/10046
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/55da47acb87d95c6b463592d3a4432d53aa055c136338efdbb63326d82a34298/getsentry/sentry-javascript/issues/10046
og:image:altWe’re going to be adding proper support for ESM in the Sentry repo. Requirement: There is no require in ESM bundles at all ESM files have .mjs file extension CJS files have .cjs file extension ### ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAbhiPrasad
hostnamegithub.com
expected-hostnamegithub.com
Nonef8d9f404447ab5df341c8a92cf5fc927730ad1321e64ac57656444d2438097f1
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3328572
octolytics-dimension-repository_nwogetsentry/sentry-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3328572
octolytics-dimension-repository_network_root_nwogetsentry/sentry-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef7edccce04851591ee529948701779ce6819bc53
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-javascript/issues/10046#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F10046
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F10046
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-javascript
Reloadhttps://github.com/getsentry/sentry-javascript/issues/10046
Reloadhttps://github.com/getsentry/sentry-javascript/issues/10046
Reloadhttps://github.com/getsentry/sentry-javascript/issues/10046
getsentryhttps://github.com/getsentry
sentry-javascripthttps://github.com/getsentry/sentry-javascript
Codehttps://github.com/getsentry/sentry-javascript
Issues339 (339)https://github.com/getsentry/sentry-javascript/issues
Pull requests58 (58)https://github.com/getsentry/sentry-javascript/pulls
Discussionshttps://github.com/getsentry/sentry-javascript/discussions
Actionshttps://github.com/getsentry/sentry-javascript/actions
Security and quality7 (7)https://github.com/getsentry/sentry-javascript/security
Insightshttps://github.com/getsentry/sentry-javascript/insights
https://github.com/getsentry/sentry-javascript
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/10046
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/10046
[v8] Update for ESM monkeypatch + ESM file structurehttps://github.com/getsentry/sentry-javascript/issues/10046#top
https://github.com/AbhiPrasad
Meta: Breakinghttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Meta%3A%20Breaking%22
8.0.0https://github.com/getsentry/sentry-javascript/milestone/15
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issue-2064936029
Node customization hookshttps://nodejs.org/api/module.html#customization-hooks
https://github.com/DataDog/import-in-the-middlehttps://github.com/DataDog/import-in-the-middle
Watch my talkhttps://www.youtube.com/watch?v=fpTa6oZR0ms
Provide a supported way to get anchored clock times open-telemetry/opentelemetry-js#3279 (comment)https://github.com/open-telemetry/opentelemetry-js/issues/3279#issuecomment-1320064182
AbhiPrasadhttps://github.com/AbhiPrasad
8.0.0https://github.com/getsentry/sentry-javascript/milestone/15
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-11384991995
AbhiPrasadhttps://github.com/AbhiPrasad
Meta: Breakinghttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Meta%3A%20Breaking%22
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-11384992163
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1876261680
https://www.npmjs.com/package/@arethetypeswrong/clihttps://www.npmjs.com/package/@arethetypeswrong/cli
https://github.com/mydea
mydeahttps://github.com/mydea
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1876616328
https://github.com/timfish
timfishhttps://github.com/timfish
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1877102996
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1877163659
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1877164826
nodejs/node#49440https://github.com/nodejs/node/issues/49440
https://github.com/mydea
mydeahttps://github.com/mydea
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1877192161
https://github.com/timfish
timfishhttps://github.com/timfish
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1877237962
https://github.com/timfish
timfishhttps://github.com/timfish
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1877533273
https://nodejs.org/api/packages.html#exportshttps://nodejs.org/api/packages.html#exports
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 4, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-11396002221
https://github.com/Lms24
Lms24https://github.com/Lms24
on Jan 5, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1878329921
#10042https://github.com/getsentry/sentry-javascript/pull/10042
https://github.com/timfish
timfishhttps://github.com/timfish
on Jan 5, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1878423673
#9199 (comment)https://github.com/getsentry/sentry-javascript/issues/9199#issuecomment-1860670538
https://github.com/timfish
timfishhttps://github.com/timfish
on Jan 6, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1879718402
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 8, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1881434264
AbhiPrasadhttps://github.com/AbhiPrasad
on Jan 18, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-11529361235
feat(node): Update and vendor `https-proxy-agent` (#10088)https://github.com/getsentry/sentry-javascript/commit/acf58d35408dced31d9613c95261c9ce4bcd3d87
#10088https://github.com/getsentry/sentry-javascript/pull/10088
acf58d3https://github.com/getsentry/sentry-javascript/commit/acf58d35408dced31d9613c95261c9ce4bcd3d87
https://github.com/GauBen
GauBenhttps://github.com/GauBen
on Jan 26, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1911745302
npmjs.com/package/@arethetypeswrong/clihttps://www.npmjs.com/package/@arethetypeswrong/cli
https://publint.dev/@sentry/nodehttps://publint.dev/@sentry/node
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jan 26, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-11606744204
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 2https://github.com/orgs/getsentry/projects/190
on Jan 26, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-14899815857
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 2https://github.com/orgs/getsentry/projects/190
on Jan 26, 2024https://github.com/getsentry/sentry-javascript/issues/10046
Lms24https://github.com/Lms24
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jan 29, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-11624146933
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 2https://github.com/orgs/getsentry/projects/190
on Jan 29, 2024https://github.com/getsentry/sentry-javascript/issues/10046
https://github.com/timfish
timfishhttps://github.com/timfish
on Feb 25, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1963027143
docs say that module customisation hookshttps://nodejs.org/api/module.html#communication-with-module-customization-hooks
https://github.com/DataDog/import-in-the-middle/blob/c3c2c52c1915b47994af59d507c59029c1f1fae9/hook.js#L302-L324https://github.com/DataDog/import-in-the-middle/blob/c3c2c52c1915b47994af59d507c59029c1f1fae9/hook.js#L302-L324
import hook registrationhttps://nodejs.org/api/module.html#enabling
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Mar 13, 2024https://github.com/getsentry/sentry-javascript/issues/10046#issuecomment-1993129703
#11067https://github.com/getsentry/sentry-javascript/issues/11067
#11066https://github.com/getsentry/sentry-javascript/issues/11066
#11070https://github.com/getsentry/sentry-javascript/issues/11070
AbhiPrasadhttps://github.com/AbhiPrasad
completedhttps://github.com/getsentry/sentry-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Mar 13, 2024https://github.com/getsentry/sentry-javascript/issues/10046#event-12096896918
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-javascript/issues/10046
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/10046
AbhiPrasadhttps://github.com/AbhiPrasad
Meta: Breakinghttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Meta%3A%20Breaking%22
GitHub Issues with 👀 2https://github.com/orgs/getsentry/projects/190
8.0.0https://github.com/getsentry/sentry-javascript/milestone/15
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.