diff --git a/.changeset/five-shrimps-repeat.md b/.changeset/five-shrimps-repeat.md new file mode 100644 index 0000000..995a10b --- /dev/null +++ b/.changeset/five-shrimps-repeat.md @@ -0,0 +1,5 @@ +--- +"@vercel/otel": patch +--- + +Strip eval() calls on Edge diff --git a/packages/otel/build.ts b/packages/otel/build.ts index 7a13445..de77285 100644 --- a/packages/otel/build.ts +++ b/packages/otel/build.ts @@ -25,6 +25,24 @@ const externalCjsToEsmPlugin: ExternalPluginFactory = (external) => ({ }, }); +// On Edge `eval()` is not allowed. Strip it from the input sources. +const stripEvalEdge: Plugin = { + name: "stripEvalEdge", + setup(builder): void { + builder.onLoad({ filter: /@protobufjs\/inquire\/index\.js/ }, () => { + return { + contents: ` + "use strict"; + module.exports = inquire; + function inquire(moduleName) { + return null; + } + `, + }; + }); + }, +}; + /** Adds support for require, __filename, and __dirname to ESM / Node. */ const esmNodeSupportBanner = { js: `import { fileURLToPath } from 'url'; @@ -71,6 +89,7 @@ async function buildAll(): Promise { external: ["@opentelemetry/api"], plugins: [ externalCjsToEsmPlugin(["async_hooks", "events", ...peerDependencies]), + stripEvalEdge, ], }), ]);