How to import or require a file outside meteor 1.2 app which uses es6 export?


#1

first some introduction to what I am doing and why:
I have 3 meteor apps and some code between them is shared, like collections, schemas and so on.
They were all meteor 1.2.1 version, but now I migrated one of them to 1.4.0.1 and moved from packages based architecture to es6 modules. But this migration of a single app took me 4 days. And until I migrate other apps, I would like to be able to reuse some already migrated code in older meteor version because otherwise I will have to face code duplication. Any suggestions ? :smiley: thank you


example scenario of my case:

I have an app with meteor release 1.2.1 on this path:

/Users/me/Meteor/my-app

and I need to require a file from my second meteor app with release 1.4.0.1

/Users/me/Meteor/my-second-app/foo.js

this is the content of foo.js

export const foo = 'hi from es6 export';

I tried to load it in the first app with

const x = Npm.require('/Users/me/Meteor/my-second-app/foo.js');

but then I get this error

 (function (exports, require, module, __filename, __dirname) { export const foo
SyntaxError: Unexpected reserved word
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.require (module.js:364:17)
at require (module.js:380:17)
...