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) 
8
  • Please give us code Commented Jan 7, 2021 at 19:24
  • You want to see my package.json? Commented Jan 7, 2021 at 19:24
  • A minimal reproducible example. Commented Jan 7, 2021 at 19:25
  • Does this answer your question? Get version number from package.json in React Redux (create-react-app) Commented Jan 7, 2021 at 19:27
  • 3
    import { Version } should be version, no? Commented Jan 7, 2021 at 19:32

1 Answer 1

0

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

import Version from "../../../package.json"; 
Sign up to request clarification or add additional context in comments.

1 Comment

This raises an error: Module not found: Error: You attempted to import ../../../package.json which falls outside of the project src/ directory

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.