During development, my application runs smoothly, and ng build --prod --source-map
successfully compiles the application. However, when attempting to access it through the browser, an error occurs:
app.module.ts:47 Uncaught ReferenceError: env is not defined
at Object.zUnb (app.module.ts:47)
at u (bootstrap:81)
Below is the relevant portion of my app.module.ts
file:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { APP_BASE_HREF } from '@angular/common';
import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { environment as env } from '@env/environment'; // <- import env
import { CoreModule } from '@app/core/core.module';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
MatSidenavModule,
CoreModule,
AppRoutingModule,
],
providers: [
{ provide: APP_BASE_HREF, useValue: env.baseHref } // <--- error
],
bootstrap: [AppComponent]
})
export class AppModule {}
Additionally, here is my tsconfig.json
file where the path for @env is defined:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src/",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"paths": {
"@app/*": ["app/*"],
"@env/*": ["environments/*"]
}
}
}