Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing js "Script error"

I'm having difficulties implementing something simple: I have an index.html file served on http://localhost:3200 by ruby on rails, which uses a javascript file served on http://localhost:8000 by webpack-dev-server.

So here's what I have:

<!doctype html>
  <head>
    <script crossorigin="anonymous" src="http://localhost:8000/app.js" />
  </head>
  <!-- ... -->
</html>

My app.js file is sent with, amongst others, the following header:

Access-Control-Allow-Origin: *

What I want is to be able to override window.onerror in app.js, and see caught errors, rather than "Script error".

What am I missing?

-- edit -- Since it might not be clear enough: my script does load. I have no problem with that. My issue is that I need to report errors that happen to somewhere else, but I can't do that since any error that occurs in app.js is reported as "Script error" rather than something more explicit.

like image 893
Nicolas SEPTIER Avatar asked Feb 01 '17 14:02

Nicolas SEPTIER


People also ask

What is js script error?

“Script error” is what browsers send to the onerror callback when an error originates from a JavaScript file served from a different origin (different domain, port, or protocol). It's painful because even though there's an error occurring, you don't know what the error is, nor from which code it's originating.

Why am I getting a JavaScript error?

There are two types of JavaScript error: Syntax Error: Occurs when there is a mistake in the way the code is written; for example, a typo or missing character. Runtime error: Occurs when the script is unable to complete its instructions; for example, if a specified object cannot be found.

How do I get rid of script error pop up Windows 10?

Remove all Temporary Internet Files. It is a good idea to delete all the cache and offline files. An outdated file may be trying to execute, resulting in an error due to conflict. Once you delete the cache, the browser will download new files, and it should resolve the script error problem.


1 Answers

What sourcemap (devtool) are you using?

I was getting this issue, and it changing from eval-source-map to source-map fixed it.

like image 169
mclin Avatar answered Sep 29 '22 13:09

mclin