vercel/pkg

Environment variables npm_package_name npm_package_version not available from package.json file

gitSambhal opened this issue · 3 comments

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

v18.16.0

What operating system are you using?

Windows

What CPU architecture are you using?

arm64

What Node versions, OSs and CPU architectures are you building for?

node18-win-x64

Describe the Bug

The following environment variables are not available while running as binary:

  • npm_package_name
  • npm_package_version

Expected Behavior

These environment variables should be present having the respective values from package.json file.

To Reproduce

console.log('process env', process.env);

I got same question.
Do you have any solution? @gitSambhal

Hi @gitSambhal
I got a solution. And share for you. Try it:

var pjson = require('../../package.json');
console.log(pjson.version);

Reference:https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code

Hi @huangganggui,
Thanks for sharing. I had used somthing similar.