chore(opentelemetry): Add worker as export | sort exports#21859
chore(opentelemetry): Add worker as export | sort exports#21859JPeer264 wants to merge 1 commit into
Conversation
| "node": { | ||
| "import": "./build/esm/index.js", | ||
| "require": "./build/cjs/index.js" | ||
| }, | ||
| "require": { | ||
| "node": { | ||
| "types": "./build/types/index.d.ts", | ||
| "default": "./build/cjs/index.js" | ||
| }, | ||
| "browser": { | ||
| "types": "./build/types/index.d.ts", | ||
| "default": "./build/cjs/index.browser.js" | ||
| }, | ||
| "types": "./build/types/index.d.ts", | ||
| "default": "./build/cjs/index.js" | ||
| "worker": { | ||
| "import": "./build/esm/index.js", | ||
| "require": "./build/cjs/index.js" | ||
| }, | ||
| "browser": { | ||
| "import": "./build/esm/index.browser.js", | ||
| "require": "./build/cjs/index.browser.js" |
There was a problem hiding this comment.
Bug: The exports order in package.json is incorrect. Generic import/require conditions appear before the browser condition, causing bundlers to select the Node.js build for browser environments.
Severity: HIGH
Suggested Fix
Reorder the exports conditions in package.json to place specific environment conditions (browser, worker, node) before the generic import and require fallbacks. This ensures that environment-specific bundlers select the correct entry point. For example, the browser condition should be evaluated before the top-level import condition.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/opentelemetry/package.json#L21-L34
Potential issue: The `exports` map in `package.json` has an incorrect condition order.
Generic conditions `import` and `require` are listed before specific environment
conditions like `browser`. According to Node.js resolution rules, the first matching
condition is used. This means browser bundlers will match the generic `import` condition
and receive the Node.js-specific build (`./build/esm/index.js`). This build imports
`node:async_hooks`, which is not available in browsers, leading to runtime errors. The
intended browser-specific build, which provides a safe stub for Node.js APIs, will be
ignored.
Did we get this right? 👍 / 👎 to inform future reviews.
| "import": "./build/esm/index.js", | ||
| "require": "./build/cjs/index.js", |
There was a problem hiding this comment.
would this not lead to these being picked over the node/browser/worker ones? 🤔 should these not be below those to be picked as fallbacks...?
There was a problem hiding this comment.
basically what the clanker found below :D
size-limit report 📦
|
In the future we need to import from
@sentry/opentelemetry. As there is now abrowserexport we go into that path, based on the wrangler's build preferences. As of now, the browser entrypoint is only here to print a warning - which would also happen on Cloudflare.In order to use the correct entrypoint in Cloudflare the
workerentry has been added.On top I also sorted the exports to match the other
package.jsons. Instead ofimport -> node -> defaultit is nownode -> import(so it is one depth less)