Repository navigation
Haste has troubles resolving modules inside @scoped modules #241
Copy link
Copy link
Closed
jestjs/jest
#6980Description
Do you want to request a feature or report a bug?
Report a bug.
What is the current behavior?
If you are outside of a @scoped/module, you can properly require() a haste module that is sitting inside @scoped/module
But if a JS file inside of @scoped/module tries to include a haste module, it's unable to resolve it.
What is the expected behavior?
Metro should be able to properly resolve Haste modules from inside scoped modules
Metro version: 0.45.1
Node version: 10.5.0
I am attempting to fix this, but haven't gotten anywhere yet. I've made a Jest test that goes inside traverseDependencies-integration-test.js to test against:
it('should work with scoped providesModuleNodeModules (haste)', async () => {
var root = '/root';
setMockFileSystem({
root: {
'index.js': `
/**
* @providesModule index
*/
require('shouldWork');
require('Bar');
`,
node_modules: {
'react-haste': {
'package.json': JSON.stringify({
name: 'react-haste',
main: 'main.js',
}),
'main.js': [
'/**',
' * @providesModule shouldWork',
' */',
].join('\n'),
},
'@org': {
module: {
'package.json': JSON.stringify({
name: '@org/module',
main: 'main.js',
}),
'main.js': '// Blank',
'Bar.js': `
/**
* @providesModule Bar
*/
require('shouldWork');
`,
},
},
},
},
});
const opts = {
...defaults,
providesModuleNodeModules: [...defaults.providesModuleNodeModules, '@org/module'],
watchFolders: [root],
};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
'/root/index.js',
);
expect(deps).toMatchSnapshot();
});
});Which fails with this error:
● traverseDependencies › node_modules (posix) › should work with scoped providesModuleNodeModules (haste)
Unable to resolve module `shouldWork` from `/root/node_modules/@org/module/Bar.js`: Module `shouldWork` does not exist in the Haste module map
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 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-*`.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
hramos commentedon Sep 11, 2018
cc @rafeca @mjesun and rest of Metro folks: @empyrical is one of our core contributors over at React Native.
rafeca commentedon Sep 12, 2018
Thanks for the really good repro steps!! 😃 I'll look at this later on the week
empyrical commentedon Sep 12, 2018
No problem! 😄
I also just tested, and it has issues with Windows - while top-level JS was able to find
Baron Unix, it wasn't able to do that on Windows. I suspect that may be an issue with the different path separators on windows. Here's a test I wrote for that too:Which fails with this:
Give RNPM the ability to look for plugins in `@scoped` modules (#21082)
Give RNPM the ability to look for plugins in `@scoped` modules (#21082)
Give RNPM the ability to look for plugins in `@scoped` modules (#21082)
Give RNPM the ability to look for plugins in `@scoped` modules (react…
Fix haste module resolution inside of scoped modules (Fixes react#241) (