1
votes

I have a config file throwing error when only building with AOT ionic cordova build android --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.ts file. The file is inside src .src/config/.env.ts

export const config: any = {
   serverUrl: "http://0.0.0.0:3000"
};
1
Can you show the code of this provider post-service.ts? - Sampath
thank you for pointing that out... I commented out the import to config file in that service... but it continues to throw the same error to the next service provider where the .env file is imported...and its imported in all the services obviously.. the following is the simplest format of how I am using the .env file: import { config } from '../config/.env'; `export class PostService { serverUrl = config.serverUrl; } - Yasir
Had the same problem and it was related to a mispelling of a file in an import for me(was Uppercase instead of lowercase) - misha130
I'm not really sure, I keep checking , things seem to be ok, since I can serve and build without AOT... perhaps the way I am exporting config as shown above... or if you suggest other ways to achieve the same purpose - Yasir

1 Answers

0
votes

It seems that on production build, its skipped files containing dot .env.. so I removed the dot env and everything got back to normal