英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论