4
votes

I'm trying to import Angular environment.ts into a different module from the app.module, specifically:

  • src (Folder)
    • app (Folder)
      • Service (Folder)
        • service.module.ts (File) <-This is where I want to import the environment
      • app.module.ts (File)
    • environment (Folder)
      • environment.ts (File) <- File which I want to import

Inside app.module this works fine:

import { environment } from '../environments/environment';

Which doesn't work inside the service.module, I have also tried:

import { environment } from 'src/environments/environment';

import { environment } from '../environments/environment';

Any ideas of how can I make this work?

3

3 Answers

6
votes

Based on your depiction of the filesystem, you need to go back up one more level.

Try import { environment } from '../../environments/environment';.

0
votes

You have to firstly navigate two folder parent. and after navigate your prefered location

../../environments/environment ..

0
votes

You have to back out 2 directories and then up to environment or environments. I am not sure because you have it spelled both ways (environment in your tree structure and environments in the paths you have tested so far)

import { environment } from './../../environment/environment';

or

import { environment } from './../../environments/environment';

Also if you are sure the path is correct but you can't import environment then you might not have prefixed the class with export.