My app depends on a library foolib, library foolibhas a dependency on lodash and requires it via var _ = require('lodash')
Requiring foolib results in lodash attaching itself to the window
I found that this was due to this:
// Some AMD build optimizers, like r.js, check for condition patterns like: if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { // Expose Lodash on the global object to prevent errors when Lodash is // loaded by a script tag in the presence of an AMD loader. // See http://requirejs.org/docs/errors.html#mismatch for more details. // Use `_.noConflict` to remove Lodash from the global object. root._ = _; Adding a debugger into the body of conditional results in the debugger triggering, but the condition that caused the if branch to be entered into now returns false
Adding a console log before the debugger to log out the value of define shows it as being defined by webpack:///(webpack)/buildin/amd-define.js?0bba with the contents of
module.exports = function() { throw new Error("define cannot be used indirect"); }; /***************** ** WEBPACK FOOTER ** (webpack)/buildin/amd-define.js ** module id = 875 ** module chunks = 2 **/ Since I'm building with webpack, it seems unexpected that that condition with define and define.amd would be true