aichholzer / attract

Requiring libraries with love. ❤️
MIT License
2 stars 0 forks source link

Cannot add path '../modules'? #3

Closed blaasvaer closed 5 years ago

blaasvaer commented 6 years ago

I need to add '../modules' as a resolve path, but it's not working.

I call 'router' from 'app/index' and need to automatically resolve (shared) modules on a higher level.

require('attract')({ basePath: '../modules'});
const Router = require('router');

Neither 'app-module-path' nor this works. Why is that, what am I totally missing about these types of modules?

aichholzer commented 6 years ago

Hello @blaasvaer -Could you please share your project's folder structure? By looking at your comment; your structure should be like this (to work):

/app
  index.js
/modules
  router.js

also, the call should be:

require('attract')({ basePath: '../modules'});
const Router = attract('router');

finally, to ensure your script is being called from the right places, you might want to resolve the right path;

require('attract')({ basePath: require('path').resolve(__dirname, '../modules')});
const Router = attract('router');

Let me know how it goes! 👍