Uncaught TypeError: can't redefine non-configurable property "$nextTick" #1940
-
Hi, I'm facing the following problem when upgrading from v2 to V3 that I can't resolve. 1. Error message from console:
Debugger points the error to this function inside Alpine.js: function injectMagics(obj, el) {
Object.entries(magics).forEach(([name, callback]) => {
Object.defineProperty(obj, `$${name}`, { // <-- error message: TypeError: can't redefine non-configurable property "$nextTick"
get() {
return callback(el, {Alpine: alpine_default, interceptor});
},
enumerable: false
});
});
return obj;
} Note: I'm not using $nextTick magic function anywhere on the project. 2. How Alpine is included to the project: Note that using the jsdelivr.net CDN and Alpine V2 the error did not occur. V2 CDN source: 3. When the error occurs: liquid: {% for product in collection %}
<div class="product-card">
<!-- Stuff and things -->
<div class="tw-border-top tw-border-brand-gray-100" x-data="window.partialPaymentCalculator" x-init="start_partial_payment('{{priceForPartialPayment}}')">
<span aria-label="Price from" class="tw-hidden md:tw-inline-block tw-text-xs tw-px-4 tw-py-2 tw-text-brand-gray-600" >Price from. <price x-text="MONTHLY_PAYMENT"></price>€/month</span>
</div>
</div>
{% endfor %} partialPaymentCalculator function: const partialPaymentCalculator = {
STATIC_TIME: 0,
STATIC_PRICE: 0,
STATIC_INTREST: 0.016, // 1,6%
STATIC_INVOICE_PAYMENT: 3.8, // €,
MONTHLY_PAYMENT: 0,
TIME_OPTIONS:[36,24,12,6,3],
calc_sum() {
const downPayments = [];
const {
STATIC_INVOICE_PAYMENT,
STATIC_INTREST,
STATIC_PRICE,
STATIC_TIME,
calc_intrest,
calc_actual_payment,
calc_debt
} = this;
let debt = STATIC_PRICE;
for(let i = 0; i < STATIC_TIME; i++) {
let intrest = calc_intrest(debt, STATIC_INTREST);
downPayments[i] = calc_actual_payment(Math.round(STATIC_PRICE/STATIC_TIME), intrest, STATIC_INVOICE_PAYMENT);
// Update debt
debt = calc_debt(Math.round(STATIC_PRICE/STATIC_TIME), debt);
}
// Return average from all
return [...downPayments].reduce((a,v,i)=>(a*i+v)/(i+1));
},
calc_debt(decrease, currentDebt) {
return Math.round(currentDebt - decrease);
},
calc_intrest(currentDebt, intrest) {
return Math.round(currentDebt * intrest);
},
calc_actual_payment(db, i, ip){
return Math.round(db + i + ip);
},
update_monthly_payment(time) {
this.set_time(time);
this.set_monthly_payment(Math.round(this.calc_sum()));
},
set_time(months){
this.STATIC_TIME = months;
},
set_price(cents) {
this.STATIC_PRICE = cents / 100;
},
get_time(){
return this.STATIC_TIME;
},
get_price() {
return this.STATIC_PRICE;
},
get_default_time(price){
if (price < 30000) {
return 3;
}
if (price >= 30000 && price < 40000) {
return 6;
}
if (price >= 40000 && price < 60000) {
return 12;
}
if (price >= 60000 && price < 100000) {
return 24;
}
if (price >= 100000) {
return 36;
}
},
start_partial_payment(price, fromDynamic = false) {
console.log(price);
if (!!fromDynamic) {
const formattedPrice = parseFloat(price) * 100;
this.STATIC_TIME = this.get_default_time(formattedPrice);
this.STATIC_PRICE = formattedPrice / 100;
} else {
this.STATIC_TIME = this.get_default_time(parseFloat(price));
this.STATIC_PRICE = parseFloat(price) / 100;
}
this.set_monthly_payment(Math.round(this.calc_sum()));
},
set_monthly_payment(sum) {
this.MONTHLY_PAYMENT = sum;
}
}
// Include partial payment calculator to window to be used via alpine or similar
window.partialPaymentCalculator = partialPaymentCalculator; Any help is greatly appreciated 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
Could you be loading the CDN twice? |
Beta Was this translation helpful? Give feedback.
-
Solution: Transform function into re-usable form: https://alpinejs.dev/directives/data#re-usable-data // Include partial payment calculator to Alpine.data for reusability
document.addEventListener('alpine:init', () => {
Alpine.data('partialPaymentCalculator', () => ({...partialPaymentCalculator}));
});
// Include partial payment calculator to Window
window.partialPaymentCalculator = {...partialPaymentCalculator}; |
Beta Was this translation helpful? Give feedback.
-
In my case it was caused by having
I just changed it to:
And it worked but I do not remember limitation that you cannot reuse store in x-data attribute in documentation. |
Beta Was this translation helpful? Give feedback.
Solution: Transform function into re-usable form: https://alpinejs.dev/directives/data#re-usable-data