react-native: Incorrect resolve js file as directory
In my project, I have directories structure like below:
/project-name
/native
/ios
index.ios.js
/src
/containers
App.js
And I require App.js
in my index.ios.js
:
var App = require('../src/containers/App');
I get a warning:
Unable to resolve module ../src/containers/App.js from /Users/username/Projects/project-name/native/index.ios.js
I thought we should not hide detail information about a happened error here:
// node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js`
const forgive = (error) => {
if (error.type !== 'UnableToResolveError') {
throw error;
}
console.warn(
'Unable to resolve module %s from %s',
toModuleName,
fromModule.path
);
return null;
};
Anyway, I add a console.error(error)
for this, and see following error message print out:
{ [UnableToResolveError: Invalid directory /Users/username/Projects/project-name/src/containers/App]
message: 'Invalid directory /Users/username/Projects/project-name/src/containers/App',
name: 'UnableToResolveError',
type: 'UnableToResolveError' }
Why require('../src/containers/App')
will try to resolve a directory there? I expected it should resolve ../src/containers/App.js
.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 17 (10 by maintainers)
I disagree with this being closed. The reason is simple. I have a react native app and web app in the same project. I would like to have the folder structure be: ‘app’ ‘web’ ‘shared’
This way I can put redux, and other shared logic between the apps in one place instead of copy and pasting. I don’t see an easy way to do this currently?