question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

I’m looking for a way to inject an app version, so it could be used by the app (for analytics, debugging, etc). Usually I use the app’s package.json, taking advantage of npm version command. But import is only allowed from within src/ as can be seen in ModuleScopePlugin.

I wanted to know if there’s another solution to this general problem (app versioning), or if the app’s package.json can just be allowed to be imported by the scope plugin

As a workaround I just created a symlink to package.json in src/, which is nice, in a way, because you can see the app is dependent on it, but for me it’s a common pattern (using the package.json), so maybe it’s better just to allow it

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

20reactions
jimnielscommented, Jun 29, 2017

Just learned this little trick: you can use $npm_package_version to access the current value of version in package.json (before react-scripts strips out all the env variables). To make this work across windows and Mac, you could leverage cross-env to do:

// in package.json
"scripts": {
  "start": "cross-env REACT_APP_VERSION=$npm_package_version react-scripts start"
}

This will make the current value of version in package.json accessible from inside your project via process.env.REACT_APP_VERSION (or in public/index.html via %REACT_APP_VERSION%)

If you’re just targeting Mac, no need for cross-env. You can do:

// in package.json
"scripts": {
  "start": "REACT_APP_VERSION=$npm_package_version react-scripts start"
}
9reactions
mooscommented, Oct 20, 2017

BEWARE: import { version } from '../package.json' exposes the whole of package.json in the build bundle, not just the version!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Version your app - Android Developers
Set app version information. To define the version information for your app, set values for the version settings in the Gradle build files:....
Read more >
App Version Software Updates - Apps on Google Play
With this app, you can easily find out which app (installed in your device) has latest update version available on Playstore. The app...
Read more >
App version numbers - IBM
The app version that displays in the app store, and it is the first number that is displayed in MobileFirst Quality Assurance. In...
Read more >
App Version | Cordova Plugin App Version to Read Ionic Apps
The App Version feature reads the version of your Ionic app from the target build settings. Usage requires the cordova-plugin-app-version.
Read more >
How To Find Out What Version of An Android App You're ...
Sometimes on Android, you need to know the version of a particular app you are running. Here's how to find the info you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found