I am following the code from here which doesn't mention any special requirements apart from Node.js being version 8.9 or higher. I am new to javascript and I am unsure as to why the import function does not work unless there are additional requirements not specified in the link.
I am getting a syntax error when I try to use 'import' in javascript:
import * as tf from '@tensorflow/tfjs'
import {generateData} from './data';
which returns the error:
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
I know that in older versions there used to be problems with the import but I am using the up to date versions for node, npm, and yarn so I am not sure why I am getting this error. The snippet of code that I am running on says that it requires node.js of version 8.9 or higher (which is satisfied) as well as either npm or yarn.
node -v
v8.10.0
npm -v
6.1.0
yarn -v
1.7.0
Also as of 2017, the import function should work in ES6 with node.js.