Skip to content

Commit

Permalink
fix(gatsby): ignore __esModule property when resolving module expor…
Browse files Browse the repository at this point in the history
…ts (#9226)
  • Loading branch information
Seldszar authored and pieh committed Oct 18, 2018
1 parent 35eacd7 commit c57f1e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -107,6 +107,10 @@ describe(`Resolve module exports`, () => {
return createElement(ReplaceComponentRenderer, { ...props, loader })
}
`,
"/esmodule/export": `
exports.__esModule = true;
exports.foo = '';
`,
}

beforeEach(() => {
Expand Down Expand Up @@ -165,4 +169,9 @@ describe(`Resolve module exports`, () => {
const result = resolveModuleExports(`/realistic/export`, resolver)
expect(result).toEqual([`replaceHistory`, `replaceComponentRenderer`])
})

it(`Ignores exports.__esModule`, () => {
const result = resolveModuleExports(`/esmodule/export`, resolver)
expect(result).toEqual([`foo`])
})
})
3 changes: 3 additions & 0 deletions packages/gatsby/src/bootstrap/resolve-module-exports.js
Expand Up @@ -75,6 +75,9 @@ module.exports = (modulePath, resolver = require.resolve) => {

if (nodeLeft.type !== `MemberExpression`) return

// ignore marker property `__esModule`
if (get(nodeLeft, `property.name`) === `__esModule`) return

// get foo from `exports.foo = bar`
if (get(nodeLeft, `object.name`) === `exports`) {
isCommonJS = true
Expand Down

0 comments on commit c57f1e0

Please sign in to comment.