Load “vanilla” Javascript Libraries Into Node.js = 'unexpected Token Export'
Solution 1:
The error 'Unexpected token export' is caused because the library is using
export default thingToExport;
instead of
module.exports = thingToExport
This is an ES6 feature not supported by Node (yet), so when Node tries to run the code, it throws an error.
How to solve: try modifying the last line of the library so it says module.exports = rsa;
.
I should add, though, that eval
is not a good way to load a library into your own code. That is what require
is for. If you have installed this library with npm i
and it is in your node_modules, you should be able to load it into your code with var rsa = require('rsa');
.
Again though, if you're not transpiling the code, it may have problems with export default
, so you will probably want to change that to module.exports
either way.
Post a Comment for "Load “vanilla” Javascript Libraries Into Node.js = 'unexpected Token Export'"