Building on related issue: Load "Vanilla" Javascript Libraries into Node.js
I'm trying to load a 'Vanilla' Javascript library 'rsa.js' into NodeJS, using the method described by Chris W. in the question above. In essence I've created a custom node_modules directory like this:
./node_modules/rsa/rsa-lib/rsa.js
./node_modules/rsa/rsa-lib/README
./node_modules/rsa/index.js
Only problem is, compiling the module fails on the last line of rsa.js:
undefined:836
export default rsa;
SyntaxError: Unexpected token export
rsa.js
var rsa = {};
(function(rsa) {
...
})(rsa);
console.log("rsa",rsa);
export default rsa;
index.js
var fs = require('fs');
// Read and eval library
filedata = fs.readFileSync('./node_modules/rsa/rsa-lib/rsa.js','utf8');
eval(filedata);
/* The rsa.js file defines a class 'rsa' which is all we want to export */
exports.rsa = rsa
Any suggestions how to fix this problem?