Failed to import user code script--Can anyone here help me??

Does anyone know what would cause this error?? It is paired with a “Failed to load resource: the server responded with a status of 504” error. My site has been down for hours due to all of this, and I don’t even know where to begin to learn about what could cause such fatal errors.

I’ll take any hints at all!

My entire family relies on the income that I make from this site, and our season is only 4 months long…WIX will break us yet. (And, yes, of course I’ve reported this and I got the run around…maybe they’ll get back to me in a few days) So, please, if anyone knows what or if anything on the front end could cause this or even if you know how to get on wix’s good side so they can help us faster, I would worship you for the advice. So as to not say a bad word, I am super -bleep- if I can’t get this running today.

Thank you!

Do you have any code? If you do - post it please.

P.S, I got such an error in the past when I used some problematic regex in my code,
But it can be other things as well.

Oh, goodness, way, way too much code. And, I’m worried that the infrastructure cannot handle the project. Granted, I am very new to this, so I know there’s many ways for me to yet lighten the load through backend modules and public files. I have started to do that and can continue down that road, but with this recent issue, I’m starting to despair and thinking that no amount of tweaking will fix this as my project requires more than wix can handle…(please tell me I’m wrong!:wink:

However, it may still be my messy code that had a hand in it (which leaves hope as that could be remedied.)

These errors started creeping in as I started my custom store pages about 10 days ago. At first, many “PlatformError: rejected handling callbacks from stale contexts.” I couldn’t find much on these errors, and since they weren’t effecting the functionality, I let them slide.

Then the "Ambassador client request failed: http status: 404"s started. These had something to do with my attempt to create my own cart icon through code on the master page. It seemed that these errors had something to do with empty carts, and I am happy to share that code (as it’s short), and I know it’s off. (it needs some sort of error catch and something to deal with the scenario of empty carts.) Here’s that code:

import { cart } from 'wix-stores'

$w.onReady(function () {
  cart.getCurrentCart()
  .then((currentCart) => {
  const cartLineItems = currentCart.lineItems.length;
      $w('#cartCount').text = cartLineItems.toString();
  });
    cart.onChange((changedCart) => {
      const cartLineItems = changedCart.lineItems.length;
      $w('#cartCount').text = cartLineItems.toString();
  cart.hideMiniCart();
  });
});

//close minicart(not yet implemented)
 //$w('#closeCartStrip').onClick((event) => {
   // $w('#columnStrip28').hide();
   // $w('#wixChat1').show();
 // });

But, as that error also was not messing with the functionality, I was plowing ahead with my store pages (thinking to go back to the master page/mini cart stuff next.

Then, last night, the “failure to import scripts” errors started, which have rendered the site useless. I have no idea if this new issue is related to the master page. The code on my store pages is raw, heavy, and I have not yet created any backend or public files to increase efficiency. (there’s plenty of redundancy in it and stupid/amateurish ways of dealing with the json stuff.) I’d love to share that code as well, if you’re up for it! Caveat: it’s 750 lines long!

Thank you so much for responding! Any advice at this point is welcome!!
All the best,
Nicky
(Centgraf Farms)

Good, that means this error might be my fault, which is hopeful!!

@nicolecentgraf The “stale content”-thing is something that happened to me too sometimes and I never got a clear answer about the cause. That’s why I am following every entry about this subject.
On “failed to load user scripts”. Happened to me too. Even a simple $w('#onReady) with "console.log(“Hello world”) would not work and generate the same error.
I solved it by contacting support and they somehow got Velo started again on my (and maybe other people’s) domains. Code length?? I wonder. Have several backend files of over 5000 lines, frontend over a 1000, usually no problem.
My advise: keep the pressure on Support, they should be able to solve it. If I had to put money on it, I would say it’s a Wix problem, not ours.

@giri-zano the “stale” issue happens to me (sometimes) after I open a lightbox (and after I close it, keeps happening on on every page navigation).
Do you see that as well?

(Anyway, I don’t see any misbehaver effect, just a log)

I don’t see the problem. But you can remove each line, one by one, and look at the errors to locate the problematic line.

Ironically, that’s exactly how I got on to this current front-end-code-heavy rendition of my store pages and mini cart…I was trying to avoid using a lightbox that seemed to be causing these stale content errors (I thought maybe that’s why they’re so slow and avoiding them would speed it up.) But, now, no lightboxes but still the error.

Ah, wait, there is a temporary active lightbox on my home page. Maybe shutting that thing down will stop it…I’ll try.

You were not wrong…my code is loading now without me touching it (and I was seeing the “failed import scripts” on pages with very simple code.) Obviously, was a wix thing. BUT, was it a wix thing that I somehow triggered (and that I could, therefore, prevent)?

So, then three questions:

  1. Are the progression of these errors related or just a fun little coincidence? …stale content, http:404s from the cart “query”, the the fail to import scripts.

  2. Should I be busting my butt to get more of my front end code in the back?I currently have about 600 lines in backend/public and about 10,000 lines front-end. I don’t even know if it’s total front-end code that counts or just per page…most of my per page load runs 200-800 lines, but I do have one that is 1300. (Oddly, the 1300 line page runs the smoothest;)

  3. Would either of you be interested in checking out my new “store page” code. It’s my most recent, and I struggled a lot (wrote some pretty wacky loops) while trying to access the product variant info. The error stuff popped up since I wrote this code (but, maybe it was from putting that temporary lightbox on my home page…also done about 10 days ago.)

Lol, if you do, please be kind…I’m a vegetable farmer, not a coder! :stuck_out_tongue:

Lol, because you magically fixed it by looking for the error…that’s how these things work, right?

Magic! It was the lightbox on the homepage! Took it down, no more errors! So, ultimately, it was not our fault. Still curious if the errors had any relation to the final error of not importing any of my user code. Maybe the Support will shed some light.

Thank you for the hint!!!

That may give you a direction…

What may give me a direction? Removing the code line by line? Sorry, confused by what you were referring to…

Yes. If you comment out each line (another line each time), and look at the console, you may find which line causes the error, and then you can think of a solution.
You can also add a debugger; line after each line to catch the error.

Yeah, that I do constantly…I call it throwing blank at the wall and seeing if it sticks. What’s this “debugger”??

Anyways, you were right, it wasn’t my code. It was the lightbox causing the error. But I still don’t know what caused the “Failed to import scripts” terror.

debugger; is a statement you can put after the line (it will have a yellow line beneath - ignore it) that lets you run the code line by line (it will stop when it reach the debugger). see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger

Anyway, you have 2 types of errors:

  1. The stale contexts which comes with the lightbox and you can ignore it as it has no effect.

  2. The ‘failed to import’ which is probably due to your code and you should debug your code and find where the problem is.

Thank you–I will try happily to debug my code some more then…maybe your debugging method will make smtg appear that I’ve missed. But, honestly, I’m just pleading for a second pair of eyes ::).

However, I think we proved that it wasn’t my code causing the “failed to import” since, without touching it, it was magically healed after 12 hours. I’m just trying to understand how the same exact code could trigger a failed to import for 12 hours and then just magically not have any errors. My guess is that it was Wix’s infrastructure…sure my site is heavy, but it’s not broken. I am just wondering what would cause this error, and if there was anything someone could see that could be triggering the crash…Something in my style of code (aka is there a more efficient way of doing what I did? ) I’ve been debugging this stuff all along. (I just delete all my console.logs so as not to add any extra weigh to the thing.)

In other words, maybe I should scrap some plans if Wix plans on pulling this stuff on me regularly. This is not a hobby for me.

And, I cannot fail to mention how irritated I am getting at how everyone at Wix support just assumes that I’m a flipping idiot. I’m guessing it’s because I’m a girl. Come on, console.log…really? I’m trying to move a step beyond the inane, thank you very much. It’d be nice to get an iota of respect.