在React中找到控制台中的错误相关行。

huangapple go评论56阅读模式
英文:

Find the relevant line of error in console in React

问题

打开开发者工具查找浏览器中的错误时,通常会看到类似以下内容:

无法读取 null 的属性 .... app.js:123123

在 MyComponent 中

虽然控制台告诉我错误发生在 MyComponent 中,但它告诉我该行位于 app.js:123123,我认为这是已构建的 JavaScript 文件,因此很难找到错误发生在哪一行。

我尝试使用错误边界和 try-catch console.log error.stack,但它没有提供确切的组件和行号。

英文:

When I open the devtools to find out where the error occured in browser, then I typically see something like this:

Cannot read properties of null .... app.js:123123

at MyComponent

It is ok that console gives me that the error occured in MyComponent , but it gives me that the line was in app.js:123123 which is the builded js file I think, so it is hard to find in which line was the error.

I tried using Erorboundaries and try-catch console.log error.stack but it did not gave me exact component with the line.

答案1

得分: 0

当启用GENERATE_SOURCEMAP时,将在“缩小”/“转译”后的JS文件旁边捆绑您的应用程序的完整源代码副本。

如果您启用此选项(GENERATE_SOURCEMAP=true),原始源文件将对您的应用程序访问者可见,使用诸如浏览器“开发工具”之类的工具。

如果您关闭它(GENERATE_SOURCEMAP=false),则在构建项目时不会创建源映射文件(在CRA的生产模式下默认生成源映射)。有关更多参考信息,我附上了链接 reference

英文:

When the GENERATE_SOURCEMAP is enabled a full copy of your app's source code is bundled alongside the "minified" / "transcompiled" version of JS files.

If you enable this (GENERATE_SOURCEMAP=true), the original source files will be visible to your app's visitors using tools like browser "Dev Tools".

And if you turn it off (GENERATE_SOURCEMAP=false), it won't create the source map files when you build your project (source maps are generated by default in production mode in CRA). for more refence i am attaching the link reference

huangapple
  • 本文由 发表于 2023年6月15日 16:40:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定