0

I have a task of adding a version number to the UI in a react web app. Since my package.json file does contain a version number is it possible to use that value as a variable in my app? Ive tried importing the package.json but this does not work. Im not sure how I should approach this in a web app any advice would be helpful. This is the beginning of my package.json where the version number lives:

{
  "name": "emr",
  "version": "1.0.0",
  "description": "Reliant EMR",
  "main": "index.js",
...

Ive tried importing the package.json like this:

import React, { Component } from "react";
import { connect } from "react-redux";
import { Version } from "../../../package.json"

I've started this by only trying to get the value out of the Version

console.log(Version.version)
CourtneyJ
  • 458
  • 6
  • 19

1 Answers1

0

You don't need the {} in this case. Version is not exported. Just remove the brackets and use

import Version from "../../../package.json";
new Q Open Wid
  • 2,225
  • 2
  • 18
  • 34
  • This raises an error: Module not found: Error: You attempted to import ../../../package.json which falls outside of the project src/ directory – matdev Jul 18 '23 at 13:49