OP EDIT: If anyone else comes across this: the app was created using create-react-app, which limits importing to within the src folder. However if you upgrade react-scripts to v1.0.11 it does let you access package.json.
I’m trying to get the version number from package.json in my app.
I’ve already tried these suggestions, but none of them have worked as I can’t access package.json from outside the src folder (might be due to React, I’m new to this). Moving package.json into src then means I can’t run
npm version minor, and
npm run build from my root folder. I’ve tried using
process.env.npm_package_version but that results in undefined.
I’m using Jenkins, and I haven’t set it up to push the commits up yet, but the only idea I have is to get the version from the tags in GitLab, but I have no idea how to do that, and it would add unnecessary dependency to the repo, so I would really like to find an alternative.
My file structure is like:
--> RootAppFolder |--> build |--> node_modules |--> public |--> src |--> Components |--> Root.js | |--> package.json
So to access package.json from Root.js I have to do
import packageJson from './../../package.json' and then I get the following error:
Module not found: You attempted to import
./../../package.json which falls outside of the project src/
directory. Relative imports outside of src/ are not supported. You can
either move it inside src/, or add a symlink to it from project’s