简体   繁体   English

使用Chrome中的React Native调试ES6导入语句

[英]Debugging ES6 import statements with React Native in Chrome

I rely heavily on React Native's "Debug in Chrome" feature and hence on Chrome's debugger. 我非常依赖React Native的“Chrome in Debug”功能,因此依赖于Chrome的调试器。 But I've noticed a huge flaw with this system: modules that I import using an ES6-style import are not visible in the scope in Chrome even though the code executes fine. 但是我注意到这个系统存在一个巨大的缺陷:我使用ES6风格的导入导入的模块在Chrome的范围内是不可见的,即使代码执行正常。 This makes debugging code using these import statements very difficult. 这使得使用这些import语句调试代码变得非常困难。

If I replace an import statement with a var MyModule = require(...) then the module is visible in the scope. 如果我用var MyModule = require(...)替换import语句,那么该模块在范围内可见。

After reading ES6 module import is not defined during debugger I took a look at the transpiled source code produced by React Native (by loading http://localhost:8081/index.ios.bundle?platform=ios&dev=true in my browser) and noticed that the module in question is loaded under a different name: 在阅读ES6模块后, 在调试器中没有定义导入我查看了React Native生成的转换源代码(通过在我的浏览器中加载http://localhost:8081/index.ios.bundle?platform=ios&dev=true )和注意到有问题的模块是以不同的名称加载的:

var _MyModule = require('MyApp/MyModule.js');
var _MyModule2 = babelHelpers.interopRequireDefault(_MyModule);

and indeed I can use _MyModule2 in Chrome. 事实上我可以在Chrome中使用_MyModule2 I have a couple of related questions: 我有几个相关的问题:

  1. Source maps seem like an amazing technology! 源地图看起来像一个惊人的技术! Why don't they support mapping variable names too? 他们为什么不支持映射变量名呢?
  2. Is there any way to make debugging with import statements easier in Chrome with React Native? 在使用React Native的Chrome中,有没有办法更轻松地使用import语句进行调试? For instance, I'm used to just moving my mouse over a variable in Chrome to see the value, but this is no longer possible with these imports. 例如,我习惯于将鼠标移动到Chrome中的变量上以查看值,但这些导入不再可能。 ( Debugging with chrome with es6 suggests enabling #enable-javascript-harmony in Chrome and turning off source maps but given the Flow code and uglification I doubt this would work well.) 使用带有es6的chrome进行调试建议在Chrome中启用#enable-javascript-harmony并关闭源地图,但考虑到Flow代码和uglification,我怀疑这样做会很好。)

Thank you. 谢谢。

I have enabled Chrome experimental features in Chrome flags and I have no problem using an ES6-style import. 我在Chrome标记中启用了Chrome实验性功能,使用ES6样式的导入时没有问题。 If you haven't, type chrome://flags in your address bar and look for Experimental JavaScript . 如果还没有,请在地址栏中键入chrome://flags并查找Experimental JavaScript This should solve your problem. 这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM