Skip to content

Commit 5bfb878

Browse files
selbekkgaearon
authored andcommitted
Add note about mistaken named / default export (#11505)
This commit adds a note about the possibility of erroneously mistaking named and default exports to an existing error message.
1 parent ac0e670 commit 5bfb878

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

packages/react-dom/src/__tests__/ReactComponent-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ describe('ReactComponent', () => {
342342
'Element type is invalid: expected a string (for built-in components) ' +
343343
'or a class/function (for composite components) but got: undefined. ' +
344344
"You likely forgot to export your component from the file it's " +
345-
'defined in.',
345+
'defined in, or you might have mixed up default and named imports.',
346346
);
347347

348348
var Y = null;
@@ -380,7 +380,8 @@ describe('ReactComponent', () => {
380380
'Element type is invalid: expected a string (for built-in components) ' +
381381
'or a class/function (for composite components) but got: undefined. ' +
382382
"You likely forgot to export your component from the file it's " +
383-
'defined in.\n\nCheck the render method of `Bar`.',
383+
'defined in, or you might have mixed up default and named imports.' +
384+
'\n\nCheck the render method of `Bar`.',
384385
);
385386

386387
// One warning for each element creation

packages/react-reconciler/src/ReactFiber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export function createFiberFromElement(
332332
) {
333333
info +=
334334
' You likely forgot to export your component from the file ' +
335-
"it's defined in.";
335+
"it's defined in, or you might have mixed up default and named imports.";
336336
}
337337
const ownerName = owner ? getComponentName(owner) : null;
338338
if (ownerName) {

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ describe('ReactIncrementalErrorHandling', () => {
749749
'Element type is invalid: expected a string (for built-in components) or ' +
750750
'a class/function (for composite components) but got: undefined. ' +
751751
"You likely forgot to export your component from the file it's " +
752-
'defined in.\n\nCheck the render method of `BrokenRender`.',
752+
'defined in, or you might have mixed up default and named imports.' +
753+
'\n\nCheck the render method of `BrokenRender`.',
753754
),
754755
]);
755756
expect(console.error.calls.count()).toBe(1);
@@ -794,7 +795,8 @@ describe('ReactIncrementalErrorHandling', () => {
794795
'Element type is invalid: expected a string (for built-in components) or ' +
795796
'a class/function (for composite components) but got: undefined. ' +
796797
"You likely forgot to export your component from the file it's " +
797-
'defined in.\n\nCheck the render method of `BrokenRender`.',
798+
'defined in, or you might have mixed up default and named imports.' +
799+
'\n\nCheck the render method of `BrokenRender`.',
798800
),
799801
]);
800802
expect(console.error.calls.count()).toBe(1);
@@ -810,7 +812,7 @@ describe('ReactIncrementalErrorHandling', () => {
810812
'Element type is invalid: expected a string (for built-in components) or ' +
811813
'a class/function (for composite components) but got: undefined. ' +
812814
"You likely forgot to export your component from the file it's " +
813-
'defined in.',
815+
'defined in, or you might have mixed up default and named imports.',
814816
);
815817

816818
ReactNoop.render(<span prop="hi" />);

packages/react/src/ReactElementValidator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export function createElementWithValidation(type, props, children) {
285285
) {
286286
info +=
287287
' You likely forgot to export your component from the file ' +
288-
"it's defined in.";
288+
"it's defined in, or you might have mixed up default and named imports.";
289289
}
290290

291291
var sourceInfo = getSourceInfoErrorAddendum(props);

packages/react/src/__tests__/ReactElementValidator-test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ describe('ReactElementValidator', () => {
274274
'Warning: React.createElement: type is invalid -- expected a string ' +
275275
'(for built-in components) or a class/function (for composite ' +
276276
'components) but got: undefined. You likely forgot to export your ' +
277-
"component from the file it's defined in.",
277+
"component from the file it's defined in, or you might have mixed up " +
278+
'default and named imports.',
278279
);
279280
expectDev(console.error.calls.argsFor(1)[0]).toBe(
280281
'Warning: React.createElement: type is invalid -- expected a string ' +
@@ -295,7 +296,8 @@ describe('ReactElementValidator', () => {
295296
'Warning: React.createElement: type is invalid -- expected a string ' +
296297
'(for built-in components) or a class/function (for composite ' +
297298
'components) but got: object. You likely forgot to export your ' +
298-
"component from the file it's defined in.",
299+
"component from the file it's defined in, or you might have mixed up " +
300+
'default and named imports.',
299301
);
300302
React.createElement('div');
301303
expectDev(console.error.calls.count()).toBe(5);
@@ -511,7 +513,8 @@ describe('ReactElementValidator', () => {
511513
'Warning: React.createElement: type is invalid -- expected a string ' +
512514
'(for built-in components) or a class/function (for composite ' +
513515
'components) but got: undefined. You likely forgot to export your ' +
514-
"component from the file it's defined in.\n\nCheck your code at **.",
516+
"component from the file it's defined in, or you might have mixed up " +
517+
'default and named imports.\n\nCheck your code at **.',
515518
);
516519
});
517520
});

packages/react/src/__tests__/ReactJSXElementValidator-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ describe('ReactJSXElementValidator', () => {
330330
'Warning: React.createElement: type is invalid -- expected a string ' +
331331
'(for built-in components) or a class/function (for composite ' +
332332
'components) but got: undefined. You likely forgot to export your ' +
333-
"component from the file it's defined in." +
333+
"component from the file it's defined in, or you might have mixed up " +
334+
'default and named imports.' +
334335
'\n\nCheck your code at **.',
335336
);
336337
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(

0 commit comments

Comments
 (0)