I'm trying to access process.env.npm_package_version in vite.config.ts. It works in dev, but in production it's says that it's undefined.
export default defineConfig({
define: {
__VERSION__: JSON.stringify(process.env.npm_package_version),
},
});
Having logged process.env, all the NPM env vars are missing in production. Is there any way to access it?
A workaround to get the version would be the following:
import * as fs from 'node:fs'
const packageJson = fs.readFileSync('./package.json', 'utf-8')
const version = JSON.parse(packageJson).version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With