Friday, 9 June 2017

How can I require react components from a globally installed node app?

So I got a package that needs to be installed globally and that takes user defined react components and renders them. I use babel-register and define:

require('babel-register')({
    presets: [
        'es2015',
        'stage-0',
        'react',
    ],
});

Now because those user defined react components sometimes live in places that don’t have a .babelrc installed or any of the packages, I would really like to use the ones that have been installed globally with the package dependencies. I'm trying to avoid having to install those dependencies when you got my package installed globally. Though not sure how.

I get this error: Couldn't find preset "es2015" relative to directory.

Installing locally works but I can't use the bin binding and some other features I would like to add.

I tried to play around with the ignore or only options but to no success.

So I guess the question is: How can I import react components and babelfy them from a folder that is far away from my own node_modules folder with all the babel packages?



via Dominik

No comments:

Post a Comment