Fixing js “Script error”

元气小坏坏 提交于 2019-12-23 09:57:43

问题


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.


回答1:


What sourcemap (devtool) are you using?

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




回答2:


This is a google chrome issue, should be when Chrome 71 is released.

Here are the relevant issue threads:

  • https://bugs.chromium.org/p/chromium/issues/detail?id=765909

  • https://github.com/webpack/webpack/issues/5681

Edit: This also impacts electron users.



来源:https://stackoverflow.com/questions/41982501/fixing-js-script-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!