Skip to content

Commit

Permalink
Fix @opentelemetry/api aliasing for webpack (vercel#64085)
Browse files Browse the repository at this point in the history
Next creates an alias for `@opentelemetry/api` to a prebundled version
[here](https://github.com/vercel/next.js/blob/a9f85d14c0187a0a3dd08468bcb9d2be3cb4be40/packages/next/src/build/create-compiler-aliases.ts#L108-L110).
However, there's a bug in `hasExternalOtelApiPackage` - it currently
always fails to remove `@opentelemetry/api/package.json` because it's
not one of the exports.
  • Loading branch information
dvoytenko authored Apr 5, 2024
1 parent 2f567da commit b953257
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { yellow, bold } from '../lib/picocolors'
import crypto from 'crypto'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import path from 'path'
import semver from 'next/dist/compiled/semver'

import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import { WEBPACK_LAYERS, WEBPACK_RESOURCE_QUERIES } from '../lib/constants'
Expand Down Expand Up @@ -269,29 +268,13 @@ export async function loadProjectInfo({
}
}

function getOpenTelemetryVersion(): string | null {
export function hasExternalOtelApiPackage(): boolean {
try {
return require('@opentelemetry/api/package.json')?.version ?? null
require('@opentelemetry/api')
return true
} catch {
return null
}
}

export function hasExternalOtelApiPackage(): boolean {
const opentelemetryVersion = getOpenTelemetryVersion()
if (!opentelemetryVersion) {
return false
}

// 0.19.0 is the first version of the package that has the `tracer.getSpan` API that we need:
// https://github.com/vercel/next.js/issues/48118
if (semver.gte(opentelemetryVersion, '0.19.0')) {
return true
} else {
throw new Error(
`Installed "@opentelemetry/api" with version ${opentelemetryVersion} is not supported by Next.js. Please upgrade to 0.19.0 or newer version.`
)
}
}

const UNSAFE_CACHE_REGEX = /[\\/]pages[\\/][^\\/]+(?:$|\?|#)/
Expand Down

0 comments on commit b953257

Please sign in to comment.