babel-plugin-preval
babel-plugin-preval copied to clipboard
ReferenceError: Can't find variable: preval (React Native app)
-
babel-plugin-preval
version: 5.1.0 -
node
version: 16.12.0 -
npm
(oryarn
) version: 8.4.1
Relevant code or config
const gitHash = preval`
import GitInfo from 'react-git-info/macro';
gitInfo = GitInfo();
module.exports = gitInfo.commit.shortHash
`
My babel.config.js
file:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['babel-plugin-preval']
}
What you did: I'm trying to use preval to get the git hash and have it displayed in the app.
What happened:
ReferenceError: Can't find variable: preval
I'm not sure if there's any additional steps I need to take to have this work in React Native.
Did you find a fix?
No, I used a different method to get the git hash which worked for me. I created a gitHash
key in package.json
which I update via an npm script: "update-git-hash": "npx json -I -f package.json -e 'this.gitHash=\"$(git rev-parse --short HEAD)\"'"
.
This way I can run that script in my Github action before building and distributing my app for QA, and have it display the correct info in my app—I reference it through import { gitHash } from '../package.json'
. The default value I have for this gitHash
key is "dev" because the specific hash isn't important during development, I only needed it for QA distributions.