问题
I'm using chrome to debug react native.
When I choose "Pause On Caught Exceptions" under "source" debugging tab, the following exception always occur: TypeError: freeProcess.binding is not a function
The file in which the exception occurs:
http://localhost:8081/< Project_folder >/node_modules/react-proxy/node_modules/lodash/_nodeUtil.js
The exception is in line 18:
return freeProcess && freeProcess.binding('util');
Full code on that .js page:
var freeGlobal = require('./_freeGlobal');
/** Detect free variable `exports`. */
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Detect free variable `process` from Node.js. */
var freeProcess = moduleExports && freeGlobal.process;
/** Used to access faster Node.js helpers. */
var nodeUtil = (function() {
try {
return freeProcess && freeProcess.binding('util');
} catch (e) {}
}());
module.exports = nodeUtil;
What is the most elegant way to avoid this exception?
Thanks!
回答1:
Ok, so I've solved it temporarily.
I've changed line 18 to:
return freeProcess && (typeof freeProcess.binding === "function") && freeProcess.binding('util');
in this file:
/< Project_folder >/node_modules/react-proxy/node_modules/lodash/_nodeUtil.js
This solution is not the best, because it should be fixed in the git of the library. I think the library is lodash, but I couldn't find the file in its git - https://github.com/lodash/lodash
来源:https://stackoverflow.com/questions/40620483/react-native-debugging-exception