react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Require issue?

Open broonage opened this issue 11 years ago • 5 comments

I have some modules (non ui) which I'm using throughout my app.

I have a structure like

/root/
-index.ios.js
-/app/
--MyModule.js
-/core/
--MyModule2.js

When I refer to a module via index.ios.js, it works fine: e.g.

var MyModule = require('./app/MyModule');
...
var MyModule2 = require('./core/MyModule2');

If I try to reference a module elsewhere (i.e. in the /apps/ folder, I have a reference from MyModule to MyModule2 which is in /core/), I have to put a full path with extension:

var MyModule2 = require('MyApp/core/MyModule2.js');

I'm sure, after surfing google for answers yesterday, I had read something about this and require paths but I can't find where I read it! In any case I would like to structure my app, is it possible?

broonage avatar Aug 07 '15 16:08 broonage

I've found the need to use relative paths. *require('../SomeDir/SomeModule'). Works like a champ

jaygarcia avatar Aug 07 '15 16:08 jaygarcia

Ok great! I'll try that on Monday. I guess I can close this, thanks!

broonage avatar Aug 07 '15 17:08 broonage

👍

jaygarcia avatar Aug 07 '15 18:08 jaygarcia

@jaygarcia, it works! Cheers! :+1:

broonage avatar Aug 10 '15 08:08 broonage

I can use relative paths. Unfortunately, thousands of import lines in inherited codebase can't. What now?

rulatir avatar Apr 27 '16 11:04 rulatir