node.js - Conflicting use of babel/register -
i'm having appears conflict in babel/register between 2 local npm packages.
in package doing following:
require('babel/register'); require('index'); and in index file of same package:
require('test'); and in "test" package:
require('babel/register'); require('test/index'); this throws following error:
throw new error("only 1 instance of babel/polyfill allowed");
but if take babel/register line out of "test" package, following error in index file of "test" package:
import fs 'fs'; ^^^^^^ syntaxerror: unexpected reserved word i have tried using system.import import "test" package (using polyfill specified on babeljs site), in context, same error above. how should go importing 1 package other , preserve ability use es6 imports/exports , other es6 features?
edit: i've simplified little, still requiring "test" first package, not loading intermediary file. instead, "main" file of "test set test/index. theoretically, loading single es6 module, should able register. still above error.
as have seen, babel/register meant run once per application, , top-level application starting.
the issue facing default, require('babel/register') set system transpile files directly inside module, not process node_modules. expectation in node_modules have been compiled ahead of time when published module registry.
one option pass ignore: false option, e.g. require('babel/register')({ignore: false}); bad idea , can lead other problems. make babel transpile all files, not safe things because not javascript code guaranteed valid es6 module.
the best solution transpile test module ahead of time. if isn't going work however, can use only option specify regex or glob paths should transpiled.
Comments
Post a Comment