[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime package.json check causes breakage when bundled #1361

Closed
sidvishnoi opened this issue Oct 28, 2022 · 3 comments
Closed

Runtime package.json check causes breakage when bundled #1361

sidvishnoi opened this issue Oct 28, 2022 · 3 comments
Assignees
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@sidvishnoi
Copy link

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/@google-cloud+logging-min@10.2.0/node_modules/@google-cloud/logging-min/src/utils/instrumentation.ts:193:20)
    at createDiagnosticEntry (/node_modules/.pnpm/@google-cloud+logging-min@10.2.0/node_modules/@google-cloud/logging-min/src/utils/instrumentation.ts:115:31)
    at populateInstrumentationInfo (/node_modules/.pnpm/@google-cloud+logging-min@10.2.0/node_modules/@google-cloud/logging-min/src/utils/instrumentation.ts:87:18)
    at Log.write (/node_modules/.pnpm/@google-cloud+logging-min@10.2.0/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)
@sidvishnoi sidvishnoi added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 28, 2022
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/nodejs-logging API. label Oct 28, 2022
@losalex losalex assigned losalex and unassigned daniel-sanche Oct 29, 2022
@losalex
Copy link
Contributor
losalex commented Oct 29, 2022

Thanks @sidvishnoi for opening this issue - I prepared a fix for this just to eliminate a crash and will work later on more appropriate solution.

@losalex
Copy link
Contributor
losalex commented Oct 31, 2022

@sidvishnoi , the fix is submitted - will release it

@losalex losalex closed this as completed Oct 31, 2022
@sidvishnoi
Copy link
Author

Thanks for handling it so quickly @losalex!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants