Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to UnableToResolveError to account for different platforms. #267

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 11 additions & 2 deletions packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
const Resolver = require('metro-resolver');

const invariant = require('fbjs/lib/invariant');
const os = require('os');
const path = require('path');
const util = require('util');

Expand Down Expand Up @@ -175,6 +176,14 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
.concat(extraPaths);

const hint = displayDirPaths.length ? ' or in these directories:' : '';
const metroCacheLocation = path.join(
os.tmpdir(),
'metro-bundler-cache-*',
);
const hasteCacheLocation = path.join(
os.tmpdir(),
'haste-map-metro-4-*',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed from haste-map-react-native-packager-*, but ideally should come from the location where it's configured:

name: 'metro-' + JEST_HASTE_MAP_CACHE_BREAKER,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could get the actual cache path from jest-haste-map if it was exposed as a getter (from here).

For now, this is perfectly fine, but I would change the second part of hasteCacheLocation to haste-map-metro-* so we don't have to update the error message if we bump the JEST_HASTE_MAP_CACHE_BREAKER variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on removing the version, I'll update.

We don't have access to the HasteMap instance right? So we'd need to add it to module_map.js?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could though change a bit the code here to have the HasteMap instance here once the getter for the cache folder gets eventually added to jest-haste-map.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jest v24 is going to have a getter for the cache path 😃

The first alpha for v24 has just been published and we're going to update Metro to this alpha version soon

);
throw new UnableToResolveError(
fromModule.path,
moduleName,
Expand All @@ -186,8 +195,8 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
'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 Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.',
' 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.',
` 3. Reset Metro Bundler cache: \`rm -rf ${metroCacheLocation}\` or \`npm start -- --reset-cache\`.`,
` 4. Remove haste cache: \`rm -rf ${hasteCacheLocation}\`.`,
].join('\n'),
);
}
Expand Down