修复js“脚本错误" [英] Fixing js "Script error"

查看:28
本文介绍了修复js“脚本错误"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实现一些简单的事情时遇到了困难:我在 http://localhost:3200 通过 ruby​​ on rails,它使用 webpack-dev-server 在 http://localhost:8000 上提供的 javascript 文件.

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.

这就是我所拥有的:

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

我的 app.js 文件发送时包含以下标头:

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

Access-Control-Allow-Origin: *

我想要的是能够覆盖 app.js 中的 window.onerror,并查看捕获的错误,而不是脚本错误".

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

我错过了什么?

-- 编辑--因为它可能不够清楚:我的脚本确实加载了.对于那件事我没有任何疑问.我的问题是我需要报告发生在其他地方的错误,但我不能这样做,因为 app.js 中发生的任何错误都被报告为脚本错误"而不是更明确的错误.

-- 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.

推荐答案

你使用的是什么 sourcemap (devtool)?

What sourcemap (devtool) are you using?

我遇到了这个问题,它从 eval-source-map 更改为 source-map 修复了它.

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

这篇关于修复js“脚本错误"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆