Skip to content

Commit

Permalink
Add note about mistaken named / default export (facebook#11505)
Browse files Browse the repository at this point in the history
This commit adds a note about the possibility of erroneously
mistaking named and default exports to an existing error message.
  • Loading branch information
selbekk authored and Ethan-Arrowood committed Dec 8, 2017
1 parent 815355c commit 6071ccd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/react-dom/src/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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(<span prop="hi" />);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/__tests__/ReactElementValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand All @@ -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);
Expand Down Expand Up @@ -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 **.',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6071ccd

Please sign in to comment.