Issue with Prod build?


#1

Hi,

So I updated to the latest Ionic 3 release and now I’m getting an issue on a production build.

Is there anyway I can get more information on this error that’s being thrown?

I’ve spent a day and reduced my code down to pretty much nothing but I’m still getting the below error. It all works fine with ionic serve.

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at 0.js:1
    at 0.js:1
    at e.exports (0.js:1)
    at 0.js:1
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (0.js:1)
    at e (vendor.js:1)
    at Object.<anonymous> (0.js:1)
    at e (vendor.js:1)
    at Object.<anonymous> (0.js:1)
    at 0.js:1
    at 0.js:1
    at e.exports (0.js:1)

Thanks


#2

Sometimes things are changed. Basically you’re calling ‘.length()’ on something that more than likely doesn’t exist.

This can happen because things are changed and sometimes methods are moved. For example in a recent patch I had to perform the following update to my code:

The _native property was no longer needed, so the portions of code referencing it were throwing undefined errors. It is potentially working in ionic serve because the web browser is still comfortable with accessing that property that way.


#3

What does it say with --verbose?

Ionic serve does not run ngc. Building with --prod does. You’re probably getting an error from the Angular compiler, which is more strict than what Ionic serve uses.


#4

I’ve gone through and removed the length throughout the application, even when I’m pretty sure it’s fine, that didn’t help.

Building production with --verbose? Will try now.


#5

No errors being thrown on verbose (few warning imports), guess I’ll have a 3rd look through the code.


#6

Search for all occurrences of Array.forEach. You may not be using length explicitly. Maybe forEach or some other JS operator is using it illegally.


#7

I’ve tracked it down to a Chart.js issue, will look into it.

Thanks for the help.


#8

@Dunny Did you find a solution? I think I have the same problem as you :confused:


#9

Well - Upgrading to ‘ionic-angular 3.9.0’, added type definitions for Chart.js too:
npm install @types/chart.js --save-dev

The upgrade seems to fix the prod build problem I was having. Adding the type definitions for Chart.js solves my IDE problem of “cannot resolve symbol” at import.

see changelog for instructions.


#10

Sorry mate, I’d not been working on the project the past few days, I can report your fix sorted my issue though.

Thanks.