Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Can't find variable: preval (React Native app) #105

Open
Twinbird24 opened this issue Mar 7, 2022 · 2 comments
Open

ReferenceError: Can't find variable: preval (React Native app) #105

Twinbird24 opened this issue Mar 7, 2022 · 2 comments

Comments

@Twinbird24
Copy link

  • babel-plugin-preval version: 5.1.0
  • node version: 16.12.0
  • npm (or yarn) 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.

@nvmnghia
Copy link

nvmnghia commented Jul 7, 2022

Did you find a fix?

@Twinbird24
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants