I've built my angular application using ng build --prod
and when I tried to launch it, an error appeared saying:
Uncaught Error: Cannot enable prod mode after platform setup.
In my api.service.ts
at the top of the service I used isDevMode()
in case I am testing on localhost:
if (isDevMode()) {
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
// 'Authorization': "Basic " + btoa(user + ":" + password),
'Authorization': `Basic ${btoa(`${user}:${password}`)}`,
'Access-Control-Allow-Origin': '*'
})
};
} else {
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
})
};
}
At main.ts
:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
And at the environment.ts
:
export const environment = {
production: false
};
I tried to check this post in stack overflow but no results from it and this post on github.
EDIT
environment.prod.ts:
export const environment = {
production: true
};