TypeError: Cannot read property 'content' of undefined

I have a config file throwing error when only building with AOT --prod

Error: ./src/config/.env.ts Module build failed: TypeError: Cannot read property 'content' of undefined at Object.optimizationLoader (/Users/yasir/myApp/mobile/node_modules/@ionic/app-scripts/dist/webpack/optimization-loader-impl.js:14:24) at Object.loader (/Users/yasir/myApp/mobile/node_modules/@ionic/app-scripts/dist/webpack/optimization-loader.js:5:32) @ ./src/providers/post-service.js 15:0-40 @ ./src/app/app.module.ngfactory.js @ ./src/app/main.ts

this is the content of the .env file

   export const config: any = {
     serverUrl: ""

Are you importing files from outside src?

No, the file is inside src

Possible Solution

I believe a webpack plugin decided to no longer accepts my declaration files that had the extension .d.ts. I had a file with only type annotations named user.d.ts and I was forced to rename it to user.ts. This allowed me to get passed the error.

More Insight

I had the same error where Module build failed: TypeError: Cannot read property 'content' of undefined.

I didn’t change any of my code, this only happened after I updated @ionic/app-scripts@2.1.4. I also tried @ionic/app-scripts@2.0.2 and got the same error.

While ionic-app-scripts serve worked flawlessly, ionic-app-scripts build --prod --release stopped working.

“Properly” downgrading or updating to different versions Angular, Ionic-Angular,and @angular/cli didn’t fix the error. I was using the current versions.

  • @angular/common@4.3.6
  • Ionic-Angular@3.6.1
  • @angular/cli@1.4.3

Ionic Info:

@ionic/cli-utils  : 1.12.0
    ionic (Ionic CLI) : 3.12.0

global packages:

    cordova (Cordova CLI) : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.4
    Cordova Platforms  : android 6.2.3
    Ionic Framework    : ionic-angular 3.6.1


    Android SDK Tools : 25.2.3
    Node              : v7.4.0
    npm               : 4.0.5
    OS                : Windows 10

I’m not sure it’s that simple. I just put a foo.d.ts file in my src/app folder with the following contents:

export interface Foo {
  bar: string;

I added a property of type Foo to my home page to make sure it was being referenced somewhere. ionic build --prod worked fine.

My case my not apply to all. I’ve seen devs had this same error because of typo, or capital case mistake in an import statement, or a change needed in the tsconfig.json. I’ve double check all those problems in my case and yet didn’t fixed the compilation error. The only thing that worked was renaming the file which was really really odd.

I’ve been using @Ionic/app-scripts for more than a year, and updated to almost each upgrade. Yet I have not ran into something weird like this.