Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 5 build error "Property does not exist on type"

import { environment } from '../../environments/environment';
import { Headers } from '@angular/http';

@Injectable()
export class ProjectsService {

  private _wpBase = environment.wpBase;

ng build --prod gives me an error :

ERROR in src/app/projects/projects.service.ts(11,33): error TS2339: Property 'wpBase' does not exist on type '{ production: boolean; }'.

How can I fix this? The app works fine, I'm trying to implement Angular Universal using this guide: https://github.com/angular/angular-cli/wiki/stories-universal-rendering

like image 928
eixcs Avatar asked Jun 20 '26 17:06

eixcs


2 Answers

You probably forgot to set the wpBase property in environment.prod.ts...

Check both your environment.ts and environment.prod.ts and see if you have set the wpBase correctly.

like image 97
Kelvin Lai Avatar answered Jun 23 '26 10:06

Kelvin Lai


Quick fix is to type the environment as any:

@Injectable()
export class ProjectsService {
  private _wpBase = (environment as any).wpBase;
}

Proper fix would be to add type definition for your environment object.

interface AppEnv {
   production: boolean;
   wpBase: // whatever is the correct type
}
export const environment: AppEnv = {
  production: false,
  wpBase: // whatever is the value
};
like image 20
Tomasz Kula Avatar answered Jun 23 '26 11:06

Tomasz Kula



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!