[英]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: 我有几个相关的问题:
import
statements easier in Chrome with React Native? 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. #enable-javascript-harmony
in Chrome and turning off source maps but given the Flow code and uglification I doubt this would work well.) #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.