Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Runtime package.json check causes breakage when bundled #1361

@sidvishnoi

Description

@sidvishnoi

If @google-cloud/logging-min or @google-cloud/logging is bundled (say, via esbuild), it crashes at runtime as the instrumentation code wants to access package.json.

export function getNodejsLibraryVersion() {
if (libraryVersion) {
return libraryVersion;
}
libraryVersion = require(path.resolve(
__dirname,
'../../../',
'package.json'
)).version;
return libraryVersion;
}

getNodejsLibraryVersion should be inlined during build-step.

Environment details

  • OS: Linux / Google Cloud Functions
  • Node.js version: 16
  • npm version: 8.4.1
  • @google-cloud/logging version: 10.2.0

Steps to reproduce

  1. await log.write(entry)
  2. Bundle with esbuild (CommonJS)
Error: Cannot find module '/package.json'
Require stack:
- /workspace/index.js
- /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/loader.js
- /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at getNodejsLibraryVersion (/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/logging-min/src/utils/instrumentation.ts:193:20)
    at createDiagnosticEntry (/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/logging-min/src/utils/instrumentation.ts:115:31)
    at populateInstrumentationInfo (/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/logging-min/src/utils/instrumentation.ts:87:18)
    at Log.write (/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/logging-min/src/log.ts:980:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at logger2 (/lib/logging-gcloud.js:44:12)

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/nodejs-logging API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions