2

How i get version from package.json ? I have project angular 5 Angular-Cli: 1.6.7 and npm 5.6.0

My file enviroment.ts:

export const enviroment = {
    VERSION: require('../package.json').version 
  }

This file it is in src/app/enviroment.ts

The file package.json it is in src/package.json

When compile, the angular cannot found the file package. here is the error:

Module not found: Error: Can't resolve '../package.json'

I follow this answer, but no success here

angularrocks.com
  • 26,767
  • 13
  • 87
  • 104
Jeterson Miranda Gomes
  • 4,967
  • 2
  • 14
  • 22

1 Answers1

3

The file package.json located under src. By doing require('../package.json') you are looking in to src/app folder instead.

So you need go one level up: VERSION: require('../../package.json').version

angularrocks.com
  • 26,767
  • 13
  • 87
  • 104