I’m trying to access the npm_package_version existing environment variable in my Next.js app client through my blueprint. I’ve tried this kind of thing:
Are you referring to the npm_package_version that’s available in NPM scripts? That wouldn’t be available to a Blueprint, as it’s not a “true” environment variable and is only available in the context of Node through NPM. For example, in one of my personal apps running Node:
There’s no env var called npm_package_version:
$ echo $npm_package_version
Which means it’s also not available in plain Node:
$ nodeWelcome to Node.js v14.19.1.Type ".help" for more information.> process.env.npm_package_versionundefined
You may need to find another way to set that env var, which may be tricky if you’re looking to do it dynamically.
Depending on where you’re intending to use the env var, maybe setting it as part of the build or start command would be sufficient? For example, using the same package.json above:
Just as an aside though, because Next.js front end needs its environment vars to start with NEXT_PUBLIC in order to be accessible, is there no way to dynamically re-create “true” environment variables with this prefix without a script? Eg: