'Require' v 'Import' in the Nodejs-Sia
-
Hi Sia Community
I am playing around with the Nodejs-Sia wrapper. I noticed that I get an issue with the 'Example Usage' script provided on Github. When using the current '"import { connect } from 'sia.js'" on the first line, Node throws an "Unexpected Token Error".
However, when this first line is changed to "var sia = require('./node_modules/sia.js')", the script runs fine. The downside to this approach is that you then have to use this sia variable each time you wish to interact with the API, as opposed to using 'import' at the top of the script to 'set and forget'.
Browsing forums leads me to conclude that import is not yet supported in Node.
Is there any workaround to get import working for the wrapper?
Thanks
-
Nope.. Not really. Although named imports is a fundemantal feature in ES6, it is not implemented in Node.
So really only one option here; userequire.And using
const sia = require('sia.js')should be enough if you installed using the--saveflag.