-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue with ember-lodash when using Babel polyfill on Phantom. #104
Fix issue with ember-lodash when using Babel polyfill on Phantom. #104
Conversation
When lodash detects that `Object.defineProperty` has been modified by `core-js` polyfills, it intentionally exports `undefined` as its default export (the rest of `lodash` knows how to handle this). However, when `loader.js` detects that `exports.default === undefined` it automatically sets `exports.default = exports` (which is mega WAT). This causes the rest of the detection system that `lodash` has in place around its `_defineProperty` exporting `undefined` as default to completely fall apart. Since it expects that module to either export a function or `undefined`, when it sees that `_defineProperty.default` is truthy it simply invokes (what it thinks is a function). Due to the behavior of `loader.js`, this means that we are essentially doing: ```js let sadface = {}; sadface(); ``` Which, low and behold, when ran on Phantom emits the following error: ``` Object is not a constructor (evaluating '(0, _lodash_defineProperty['default'])') ``` Thanks to @rondale-sc for helping me debug this.
Note, I used I wrote a blog post about this a few days ago for those that are curious: http://rwjblue.com/2017/05/09/broccoli-debugging/. |
Crosslinking upstream issue in loader.js to remove this automatic default export creation: ember-cli/loader.js#114. |
Thank you! ❤️ |
Nice work 👍 |
…lt` exports If a module does not define a default export, loader.js assigns `exports.default = exports` for compatibility with modules that don't use `_interopRequireDefault` from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose [bugs][1]. We should remove `makeDefaultExport` in version 5.0. This update * adds a deprecation warning in preparation for removing `makeDefaultExport`. * adds a debug build with the deprecation enabled. Addresses ember-cli#114 [1]:mike-north/ember-lodash#104
…lt` exports If a module does not define a default export, loader.js assigns `exports.default = exports` for compatibility with modules that don't use `_interopRequireDefault` from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose [bugs][1]. We should remove `makeDefaultExport` in version 5.0. This update * adds a deprecation warning in preparation for removing `makeDefaultExport`. * adds a debug build with the deprecation enabled. Addresses ember-cli#114 [1]:mike-north/ember-lodash#104
…lt` exports If a module does not define a default export, loader.js assigns `exports.default = exports` for compatibility with modules that don't use `_interopRequireDefault` from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose [bugs][1]. We should remove `makeDefaultExport` in version 5.0. This update * adds a deprecation warning in preparation for removing `makeDefaultExport`. * adds a debug build with the deprecation enabled. Addresses ember-cli#114 [1]:mike-north/ember-lodash#104
…lt` exports If a module does not define a default export, loader.js assigns `exports.default = exports` for compatibility with modules that don't use `_interopRequireDefault` from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose [bugs][1]. We should remove `makeDefaultExport` in version 5.0. This update * adds a deprecation warning in preparation for removing `makeDefaultExport`. * adds a debug build with the deprecation enabled. Addresses ember-cli#114 [1]:mike-north/ember-lodash#104
…lt` exports If a module does not define a default export, loader.js assigns `exports.default = exports` for compatibility with modules that don't use `_interopRequireDefault` from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose [bugs][1]. We should remove `makeDefaultExport` in version 5.0. This update * adds a deprecation warning in preparation for removing `makeDefaultExport`. * adds a debug build with the deprecation enabled. Addresses ember-cli#114 [1]:mike-north/ember-lodash#104
When lodash detects that
Object.defineProperty
has been modified bycore-js
polyfills, it intentionally exportsundefined
as its default export (the rest oflodash
knows how to handle this).However, when
loader.js
detects thatexports.default === undefined
it automatically setsexports.default = exports
(which is mega WAT).This causes the rest of the detection system that
lodash
has in place around its_defineProperty
exportingundefined
as default to completely fall apart. Since it expects that module to either export a function orundefined
, when it sees that_defineProperty.default
is truthy it simply invokes (what it thinks is a function). Due to the behavior ofloader.js
, this means that we are essentially doing:Which, low and behold, when ran on Phantom emits the following error:
Thanks to @rondale-sc for helping me debug this.
Fixes #103
Fixes ember-cli/ember-cli#7001
Fixes miragejs/ember-cli-mirage#1084