From d7b56ebba76236702a9c2401eab839920b583659 Mon Sep 17 00:00:00 2001 From: Kristofer Selbekk Date: Thu, 9 Nov 2017 17:50:01 +0100 Subject: [PATCH] Add note about mistaken named / default export This commit adds a note about the possibility of erroneously mistaking named and default exports to an existing error message. --- packages/react-dom/src/__tests__/ReactComponent-test.js | 5 +++-- packages/react-reconciler/src/ReactFiber.js | 2 +- .../src/__tests__/ReactIncrementalErrorHandling-test.js | 8 +++++--- packages/react/src/ReactElementValidator.js | 2 +- .../react/src/__tests__/ReactElementValidator-test.js | 9 ++++++--- .../react/src/__tests__/ReactJSXElementValidator-test.js | 3 ++- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactComponent-test.js b/packages/react-dom/src/__tests__/ReactComponent-test.js index f65aed7e70d8d..0a63915429c2a 100644 --- a/packages/react-dom/src/__tests__/ReactComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactComponent-test.js @@ -342,7 +342,7 @@ describe('ReactComponent', () => { 'Element type is invalid: expected a string (for built-in components) ' + 'or a class/function (for composite components) but got: undefined. ' + "You likely forgot to export your component from the file it's " + - 'defined in.', + 'defined in, or you might have mixed up default and named imports.', ); var Y = null; @@ -380,7 +380,8 @@ describe('ReactComponent', () => { 'Element type is invalid: expected a string (for built-in components) ' + 'or a class/function (for composite components) but got: undefined. ' + "You likely forgot to export your component from the file it's " + - 'defined in.\n\nCheck the render method of `Bar`.', + 'defined in, or you might have mixed up default and named imports.' + + '\n\nCheck the render method of `Bar`.', ); // One warning for each element creation diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index ba06503e9cf0f..af2ce6478ea90 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -332,7 +332,7 @@ export function createFiberFromElement( ) { info += ' You likely forgot to export your component from the file ' + - "it's defined in."; + "it's defined in, or you might have mixed up default and named imports."; } const ownerName = owner ? getComponentName(owner) : null; if (ownerName) { diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index c7b082d77164d..b488208180987 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -749,7 +749,8 @@ describe('ReactIncrementalErrorHandling', () => { 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined. ' + "You likely forgot to export your component from the file it's " + - 'defined in.\n\nCheck the render method of `BrokenRender`.', + 'defined in, or you might have mixed up default and named imports.' + + '\n\nCheck the render method of `BrokenRender`.', ), ]); expect(console.error.calls.count()).toBe(1); @@ -794,7 +795,8 @@ describe('ReactIncrementalErrorHandling', () => { 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined. ' + "You likely forgot to export your component from the file it's " + - 'defined in.\n\nCheck the render method of `BrokenRender`.', + 'defined in, or you might have mixed up default and named imports.' + + '\n\nCheck the render method of `BrokenRender`.', ), ]); expect(console.error.calls.count()).toBe(1); @@ -810,7 +812,7 @@ describe('ReactIncrementalErrorHandling', () => { 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined. ' + "You likely forgot to export your component from the file it's " + - 'defined in.', + 'defined in, or you might have mixed up default and named imports.', ); ReactNoop.render(); diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index e8f422c6f6159..f4e4cf6eeb3d4 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -285,7 +285,7 @@ export function createElementWithValidation(type, props, children) { ) { info += ' You likely forgot to export your component from the file ' + - "it's defined in."; + "it's defined in, or you might have mixed up default and named imports."; } var sourceInfo = getSourceInfoErrorAddendum(props); diff --git a/packages/react/src/__tests__/ReactElementValidator-test.js b/packages/react/src/__tests__/ReactElementValidator-test.js index a376e061d0ea4..3e5e436f3e7d2 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.js @@ -274,7 +274,8 @@ describe('ReactElementValidator', () => { 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + 'components) but got: undefined. You likely forgot to export your ' + - "component from the file it's defined in.", + "component from the file it's defined in, or you might have mixed up " + + 'default and named imports.', ); expectDev(console.error.calls.argsFor(1)[0]).toBe( 'Warning: React.createElement: type is invalid -- expected a string ' + @@ -295,7 +296,8 @@ describe('ReactElementValidator', () => { 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + 'components) but got: object. You likely forgot to export your ' + - "component from the file it's defined in.", + "component from the file it's defined in, or you might have mixed up " + + 'default and named imports.', ); React.createElement('div'); expectDev(console.error.calls.count()).toBe(5); @@ -511,7 +513,8 @@ describe('ReactElementValidator', () => { 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + 'components) but got: undefined. You likely forgot to export your ' + - "component from the file it's defined in.\n\nCheck your code at **.", + "component from the file it's defined in, or you might have mixed up " + + 'default and named imports.\n\nCheck your code at **.', ); }); }); diff --git a/packages/react/src/__tests__/ReactJSXElementValidator-test.js b/packages/react/src/__tests__/ReactJSXElementValidator-test.js index f48ec718e6f62..bf189bbf78092 100644 --- a/packages/react/src/__tests__/ReactJSXElementValidator-test.js +++ b/packages/react/src/__tests__/ReactJSXElementValidator-test.js @@ -330,7 +330,8 @@ describe('ReactJSXElementValidator', () => { 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + 'components) but got: undefined. You likely forgot to export your ' + - "component from the file it's defined in." + + "component from the file it's defined in, or you might have mixed up " + + 'default and named imports.' + '\n\nCheck your code at **.', ); expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(