Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3: Build in “prod” mode: Cannot find module “.”

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
System:

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 
Misc:

backend : legacy

Thank you!

like image 413
PX Developer Avatar asked Jun 06 '18 06:06

PX Developer


3 Answers

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.

like image 154
PX Developer Avatar answered Oct 19 '22 18:10

PX Developer


Removing ^ from @ionic/app-scripts and typescript works for me as follows:

"devDependencies": {
    "@ionic/app-scripts": "3.1.9",
    "typescript": "2.8.3"
  }
like image 9
Nitish Gogate Avatar answered Oct 19 '22 18:10

Nitish Gogate


I had a similar problem, but the wrong typescript package was getting pulled in from a combination of other dependent projects as well as VS Code. I resolved it by pinning the exact version (no ^ or ~) of @ionic/app-scripts and typescript to what I needed.

"devDependencies": { "@ionic/app-scripts": "3.1.9", "typescript": "2.6.2" }

like image 3
BRass Avatar answered Oct 19 '22 20:10

BRass