Error while building iOS for production

Hello everyone

I’m trying to build my ionic app for production with the command ‘sudo ionic cordova build ios --prod’ on a Mac but I get the following error: “TypeError: Cannot read property ‘codeGen’ of undefined”.

I’ve already googled alot but that wasn’t succesfull.

My current package.json: https://hastebin.com/taxisepeno.json

I hope someone can help me,
thank you in advance

Kind regards
~smessie

Post your ionic info output please.

Why the sudo?

Does it work without --prod?

ionic info: https://hastebin.com/patomivefe.coffeescript

It works without --prod yes, forgot to mention that.

Run the same command with --verbose and post its whole output please.

Did it work before?
What is your package.json content?

package.json is in main post
With verbose:

TypeError: Cannot read property 'codeGen' of undefined
[DEBUG] TypeError: Cannot read property 'codeGen' of undefined
            at Object.doCodegen 
        (/Users/*user*/WebstormProjects/SmessieCraftApp/node_modules/@ionic/app-scripts/dist/aot/codegen.js:6:50)
            at 
        /Users/*user*/WebstormProjects/SmessieCraftApp/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:42:30

Ah, you linked it. We prefer the text to be pasted here and formatted as code with the </> button.

"@ionic/app-scripts": "2.0.2",

This could be updated to a recent version. Maybe this already fixes it.

Okay, I updated app scripts with "sudo npm install @ionic/app-scripts@latest --save-dev but still doesnt work.
devDependencies:@ionic-app-scripts in package.json is on ^2.1.4 now.

Create a new project with ionic start blank blank and see if it works there. If it does, we at least know it is not with your Ionic installation but this specific project.

blank project worked for me…

Then I am out of ideas. Did you google for the error message and do all the things they suggest?

Yeah, opened like hundert other pages, already googling since yesterday.

That error is coming from inside the angular AoT compiler. I would recommend completely removing your entire node/npm installation and the node_modules directory of your project, installing nvm, and then religiously avoiding ever running any npm/ionic things under sudo.

1 Like

Okay, didn’t know that I may not use sudo.
Removed npm and reinstalled with along with nvm but doesnt seem to help, without --prod it works but with not.

Maybe you have some strange dependency mismatch amongst ionic-app-scripts, typescript and angular. Your initial link doesn’t work for me, so I can’t say anything more specific.

{
    "name": "ionic-hello-world",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "2.2.1",
        "@angular/compiler": "2.2.1",
        "@angular/compiler-cli": "2.2.1",
        "@angular/core": "2.2.1",
        "@angular/forms": "2.2.1",
        "@angular/http": "2.2.1",
        "@angular/platform-browser": "2.2.1",
        "@angular/platform-browser-dynamic": "2.2.1",
        "@angular/platform-server": "2.2.1",
        "@ionic/storage": "^1.1.9",
        "cordova-ios": "^4.4.0",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-inappbrowser": "^1.7.1",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.1",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-sqlite-storage": "^2.0.4",
        "ionic-angular": "2.0.0",
        "ionic-native": "2.4.1",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "5.0.0-beta.12",
        "sw-toolbox": "3.4.0",
        "zone.js": "0.6.26"
    },
    "devDependencies": {
        "@angular/compiler-cli": "^2.2.1",
        "@ionic/app-scripts": "^2.1.4",
        "ionic": "3.9.2",
        "typescript": "2.0.9"
    },
    "cordovaPlugins": [
        "cordova-plugin-whitelist",
        "cordova-plugin-console",
        "cordova-plugin-statusbar",
        "cordova-plugin-device",
        "cordova-plugin-splashscreen",
        "ionic-plugin-keyboard"
    ],
    "cordovaPlatforms": [],
    "description": "SmessieCraftApp: An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-inappbrowser": {},
            "cordova-sqlite-storage": {},
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {}
        },
        "platforms": [
            "ios"
        ]
    }
}

This is my package.json now

I suspect that that current version of app-scripts can’t handle the relatively ancient angular version. Can you try bringing all the dependencies up-to-date?

I tried this multiple times but then I get a lot of other errors and even ionic cordova build ios without --prod doesn’t work then.