vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.28k stars 1.01k forks source link

Environment variables npm_package_name npm_package_version not available from package.json file #1970

Closed gitSambhal closed 8 months ago

gitSambhal commented 1 year ago

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:

Expected Behavior

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

To Reproduce

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

huangganggui commented 10 months ago

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

huangganggui commented 10 months ago

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

gitSambhal commented 10 months ago

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