admin管理员组

文章数量:1289556

So I have this simple Javascript code where I am paring database-stored cart items with client-sent new cart items. But I am getting this new error which I have never seen before:

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 178414678
#
#
#
#FailureMessage Object: 000000DCF17BE620
 1: 00007FF7F50A401F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112511
 2: 00007FF7F4FC116F v8::CFunctionInfo::HasOptions+7055
 3: 00007FF7F5C97302 V8_Fatal+162
 4: 00007FF7F5820C65 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+101
 5: 00007FF7F56CA463 v8::internal::FeedbackNexus::ic_state+62771
 6: 00007FF7F56E0FC0 v8::Message::GetIsolate+15840
 7: 00007FF7F5555681 v8::internal::CompilationCache::IsEnabledScriptAndEval+26849
 8: 00007FF7F59F34B1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
 9: 000001F9C44485C2

What the code does is, it checks if the product id is same or not in both the arrays. If it is then it will just replace the database cart item unit with client-sent cart item unit. If it is not, then it will just push the client-sent cart item to database-stored cart items array. That's all it does.

The code:

const dbCartItems = [
    { productID: '1233433', unit: 1 },
    { productID: 'asfa34wr', unit: 2 }
];

const clientCartItems = [
    { productID: 'dfhgdf46t3', unit: 4 },
    { productID: 'hgfh566', unit: 1 },
    { productID: '32523', unit: 1 }
];

for ( let i = 0; i < dbCartItems.length; i++ ) {

    for ( let j = 0; j < clientCartItems.length; j++ ) {

        if ( dbCartItems[ i ].productID === clientCartItems[ j ].productID ) {
            dbCartItems[ i ].unit = clientCartItems[ j ].unit;
        } else {
            dbCartItems.push( clientCartItems[ j ] );
        }

    }

}

console.log( dbCartItems );

Can someone please explain what is wrong with the code that it throws this kind of error which I have never seen before?

So I have this simple Javascript code where I am paring database-stored cart items with client-sent new cart items. But I am getting this new error which I have never seen before:

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 178414678
#
#
#
#FailureMessage Object: 000000DCF17BE620
 1: 00007FF7F50A401F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112511
 2: 00007FF7F4FC116F v8::CFunctionInfo::HasOptions+7055
 3: 00007FF7F5C97302 V8_Fatal+162
 4: 00007FF7F5820C65 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+101
 5: 00007FF7F56CA463 v8::internal::FeedbackNexus::ic_state+62771
 6: 00007FF7F56E0FC0 v8::Message::GetIsolate+15840
 7: 00007FF7F5555681 v8::internal::CompilationCache::IsEnabledScriptAndEval+26849
 8: 00007FF7F59F34B1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
 9: 000001F9C44485C2

What the code does is, it checks if the product id is same or not in both the arrays. If it is then it will just replace the database cart item unit with client-sent cart item unit. If it is not, then it will just push the client-sent cart item to database-stored cart items array. That's all it does.

The code:

const dbCartItems = [
    { productID: '1233433', unit: 1 },
    { productID: 'asfa34wr', unit: 2 }
];

const clientCartItems = [
    { productID: 'dfhgdf46t3', unit: 4 },
    { productID: 'hgfh566', unit: 1 },
    { productID: '32523', unit: 1 }
];

for ( let i = 0; i < dbCartItems.length; i++ ) {

    for ( let j = 0; j < clientCartItems.length; j++ ) {

        if ( dbCartItems[ i ].productID === clientCartItems[ j ].productID ) {
            dbCartItems[ i ].unit = clientCartItems[ j ].unit;
        } else {
            dbCartItems.push( clientCartItems[ j ] );
        }

    }

}

console.log( dbCartItems );

Can someone please explain what is wrong with the code that it throws this kind of error which I have never seen before?

Share Improve this question asked Mar 28, 2022 at 16:26 s.khans.khan 4053 gold badges12 silver badges36 bronze badges 1
  • 1 dbCartItems.push( clientCartItems[ j ] ); You keep increasing the length of the array inside the loop? – 001 Commented Mar 28, 2022 at 16:29
Add a ment  | 

5 Answers 5

Reset to default 3

Your plete logic is wrong. You are using nested loops and that would fetch wrong results even if you use a new array to store items in it.

Your code should look like this:

// get all product ids from dbCartItems array
const dbCartItemsProductIds = dbCartItems.map(cartItem => cartItem.productID);

for(let i=0;i<clientCartItems.length;i++) {
    const indexOfClientItemInDb = dbCartItemsProductIds.indexOf(clientCartItems[i].productID);
    // if clientCartItemProductId found in dbCartItemsProductIds
    if(indexOfClientItemInDb!== -1) {
        dbCartItems[indexOfClientItemInDb].unit = clientCartItems[i].unit;
    } else {
        dbCartItems.push(clientCartItems[i]);
    }
}

First, get all the productIds from dbCartItems (to match the productids from clientCartItems. Now, for each clientCartItems, check if the item product id is present in dbCartItemsProductIds, then change number of units, else add the item to dbCartItems.

You are continously adding to the same array which is resulting to an infinite loop. Make a new array and add items to it.

I have also faced this issue in my Angular app (upgraded from Angular version 13 to 14):

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 169242095
#
#
#
#FailureMessage Object: 000000A21E2FE930
 1: 00007FF7CCF1401F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112511
 2: 00007FF7CCE3116F v8::CFunctionInfo::HasOptions+7055
 3: 00007FF7CDB07302 V8_Fatal+162
 4: 00007FF7CD690C65 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+101
 5: 00007FF7CD53A463 v8::internal::FeedbackNexus::ic_state+62771
 6: 00007FF7CD550FC0 v8::Message::GetIsolate+15840
 7: 00007FF7CD3C5681 v8::internal::CompilationCache::IsEnabledScriptAndEval+26849
 8: 00007FF7CD8634B1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
 9: 000001D976B66A25

I have updated the version of @types/node to LTS. And this problem has been solved. I think the version was unsupportable to Angular 14v

if faced this issue in Angular-js, React-js or any other js framework.

  • delete node_modules
  • install node_modules (npm i)

move few dependencies to devDependencies.

For my react Project, solution was to:

move "react-scripts": "5.0.1" from dependencies to devDependencies in package.json

本文标签: