mirror of https://github.com/status-im/metro.git
Fix node_modules resolution error messages
Summary: We could probably relieve a lot of pain (in [this issue](https://github.com/facebook/react-native/issues/4968) specifically) by fixing the error message for when a module cannot be resolved after trying every relevant `node_modules` directory. Currently, you get a confusing error message that only gives you the last `node_modules` directory checked. By creating the error message where we can access the `searchQueue`, we're able to provide all of the attempted `node_modules` directories. Here's an example error message: ``` Unable to resolve module leftpad from /Users/aleclarson/ReactProject/src/stuff/index.js: Module does not exist in the module map or as these directories: /Users/aleclarson/ReactProject/src/stuff/node_modules/leftpad /Users/aleclarson/ReactProject/src/node_modules/leftpad /Users/aleclarson/ReactProject/node_modules/leftpad /Users/aleclarson/node_modules/leftpad /Users/node_modules/leftpad ``` Closes https://github.com/facebook/react-native/pull/9832 Differential Revision: D3895408 Pulled By: davidaurelio fbshipit-source-id: 872c9a3bb3633f751ec69b586a261616578ed511
This commit is contained in:
parent
0a93067f3a
commit
bb1666a93a
|
@ -375,11 +375,7 @@ class ResolutionRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let p = Promise.reject(new UnableToResolveError(
|
let p = Promise.reject(new UnableToResolveError(fromModule, toModuleName));
|
||||||
fromModule,
|
|
||||||
toModuleName,
|
|
||||||
'Node module not found',
|
|
||||||
));
|
|
||||||
searchQueue.forEach(potentialModulePath => {
|
searchQueue.forEach(potentialModulePath => {
|
||||||
p = this._tryResolve(
|
p = this._tryResolve(
|
||||||
() => this._tryResolve(
|
() => this._tryResolve(
|
||||||
|
@ -390,7 +386,22 @@ class ResolutionRequest {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return p;
|
return p.catch(error => {
|
||||||
|
if (error.type !== 'UnableToResolveError') {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
throw new UnableToResolveError(
|
||||||
|
fromModule,
|
||||||
|
toModuleName,
|
||||||
|
`Module does not exist in the module map ${searchQueue.length ? 'or in these directories:' : ''}\n` +
|
||||||
|
searchQueue.map(searchPath => ` ${path.dirname(searchPath)}\n`) + '\n' +
|
||||||
|
`This might be related to https://github.com/facebook/react-native/issues/4968\n` +
|
||||||
|
`To resolve try the following:\n` +
|
||||||
|
` 1. Clear watchman watches: \`watchman watch-del-all\`.\n` +
|
||||||
|
` 2. Delete the \`node_modules\` folder: \`rm -rf node_modules && npm install\`.\n` +
|
||||||
|
` 3. Reset packager cache: \`rm -fr $TMPDIR/react-*\` or \`npm start -- --reset-cache\`.`
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,13 +469,7 @@ class ResolutionRequest {
|
||||||
throw new UnableToResolveError(
|
throw new UnableToResolveError(
|
||||||
fromModule,
|
fromModule,
|
||||||
toModule,
|
toModule,
|
||||||
`Unable to find this module in its module map or any of the node_modules directories under ${potentialDirPath} and its parent directories
|
`Directory ${potentialDirPath} doesnt exist`,
|
||||||
|
|
||||||
This might be related to https://github.com/facebook/react-native/issues/4968
|
|
||||||
To resolve try the following:
|
|
||||||
1. Clear watchman watches: \`watchman watch-del-all\`.
|
|
||||||
2. Delete the \`node_modules\` folder: \`rm -rf node_modules && npm install\`.
|
|
||||||
3. Reset packager cache: \`rm -fr $TMPDIR/react-*\` or \`npm start -- --reset-cache\`.`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue