Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/metro/src/lib/TerminalReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export default class TerminalReporter {
`${error.fromModulePath}\` tries to require \`${he.hasteName}\`, ` +
'but there are several files providing this module. You can delete ' +
'or fix them: \n\n' +
Object.keys(he.duplicatesSet)
[...he.duplicatesSet.keys()]
.sort()
.map(dupFilePath => ` * \`${dupFilePath}\`\n`)
.join('');
Expand Down
25 changes: 25 additions & 0 deletions packages/metro/src/lib/__tests__/formatBundlingError-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,33 @@

import {UnableToResolveError} from '../../node-haste/DependencyGraph/ModuleResolution';
import formatBundlingError from '../formatBundlingError';
import {AmbiguousModuleResolutionError} from 'metro-core';
import FileMap, {DuplicateHasteCandidatesError} from 'metro-file-map';

describe('formatBundlingError', () => {
test('AmbiguousModuleResolutionError', () => {
const hasteError = new DuplicateHasteCandidatesError(
'target',
FileMap.H.GENERIC_PLATFORM,
false,
new Map([
['/root/a.js', FileMap.H.MODULE],
['/root/b.js', FileMap.H.MODULE],
]),
);
expect(
formatBundlingError(
new AmbiguousModuleResolutionError('/origin/module.js', hasteError),
),
).toMatchObject({
type: 'AmbiguousModuleResolutionError',
message:
"Ambiguous resolution: module '/origin/module.js' tries to require " +
"'target', but there are several files providing this module. You " +
'can delete or fix them: \n\n/root/a.js\n\n/root/b.js',
});
});

test('UnableToResolveError', () => {
expect(
formatBundlingError(
Expand Down
5 changes: 1 addition & 4 deletions packages/metro/src/lib/formatBundlingError.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export default function formatBundlingError(
`${error.fromModulePath}\' tries to require \'${he.hasteName}\', but ` +
'there are several files providing this module. You can delete or ' +
'fix them: \n\n' +
Object.keys(he.duplicatesSet)
.sort()
.map(dupFilePath => `${dupFilePath}`)
.join('\n\n');
[...he.duplicatesSet.keys()].sort().join('\n\n');

return {
type: 'AmbiguousModuleResolutionError',
Expand Down
Loading