Build in "prod" mode: Cannot find module "."


Hi everyone,

we have a large Ionic app that we’re trying to build in production mode since it’s almost ready. The first issue we found is that we were getting a “JavaScript heap out of memory” error when compiling, but we fixed it by giving more memory to node:

"ionic:build": "node --max-old-space-size=16384 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",

npm run ionic:build -- --prod

With this command the app successfully builds, but if I open it I get the following error:

Uncaught Error: Cannot find module “.”
at vendor.js:1
at vendor.js:1
at Object. (vendor.js:1)
at e (vendor.js:1)
at Object. (main.js:1)
at e (vendor.js:1)
at window.webpackJsonp (vendor.js:1)
at main.js:1

I searched a bit and I found that it could be caused by require, but we aren’t using it. Any idea of what could be going on or what we can do to debug the issue? Is there any way to use “–prod” without minifying the JS?

This is my environment:

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 6.5.0 
Gulp CLI              : [09:06:54] CLI version 3.9.1 [09:06:54] Local version 3.9.1

local packages:

@ionic/app-scripts : 3.1.9
Cordova Platforms  : android 6.1.2 ios 4.3.1
Ionic Framework    : ionic-angular 3.9.2


Android SDK Tools : 25.2.5
ios-deploy        : 1.9.1 
ios-sim           : 5.0.8 
Node              : v8.6.0
npm               : 5.3.0 
OS                : macOS High Sierra
Xcode             : Xcode 9.3.1 Build version 9E501 


backend : legacy

I also tried building like this:

npm run ionic:build -- --aot

But then I get an error saying it doesn’t find one of my providers (it is declared in app/app.module.ts).

Thank you!


I found the problem. In my package.json I was using:

"typescript": "^2.9.1",

Decreasing the version to ~2.6.2 fixed it for me. Now I’m getting another error, but I’ll open a new topic for that.


I downgraded to ^2.7.2, and the error was gone. :tada:


I have the same problem, but if I downgrade to less than typescript 3 I screw up my angular 7 dependency. Isn’t thare any patch for this problem? I read something about this having to do with angular’s ahead of time compiler…


Trying to use Angular 7 with Ionic 3 is also unsupported, so you may want to look into moving to the Ionic 4 beta.