Unverified Commit b953257c authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

Fix @opentelemetry/api aliasing for webpack (#64085)

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.
parent 2f567da8
...@@ -4,7 +4,6 @@ import { yellow, bold } from '../lib/picocolors' ...@@ -4,7 +4,6 @@ import { yellow, bold } from '../lib/picocolors'
import crypto from 'crypto' import crypto from 'crypto'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import path from 'path' import path from 'path'
import semver from 'next/dist/compiled/semver'
import { escapeStringRegexp } from '../shared/lib/escape-regexp' import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import { WEBPACK_LAYERS, WEBPACK_RESOURCE_QUERIES } from '../lib/constants' import { WEBPACK_LAYERS, WEBPACK_RESOURCE_QUERIES } from '../lib/constants'
...@@ -269,29 +268,13 @@ export async function loadProjectInfo({ ...@@ -269,29 +268,13 @@ export async function loadProjectInfo({
} }
} }
function getOpenTelemetryVersion(): string | null { export function hasExternalOtelApiPackage(): boolean {
try { try {
return require('@opentelemetry/api/package.json')?.version ?? null require('@opentelemetry/api')
return true
} catch { } catch {
return null
}
}
export function hasExternalOtelApiPackage(): boolean {
const opentelemetryVersion = getOpenTelemetryVersion()
if (!opentelemetryVersion) {
return false 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[\\/][^\\/]+(?:$|\?|#)/ const UNSAFE_CACHE_REGEX = /[\\/]pages[\\/][^\\/]+(?:$|\?|#)/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment