Error importing tensorflow js in node

0

I want to use tensorflowjs in the terminal and I copy the code from the npm page and I get an error:

(function (exports, require, module, __filename, __dirname) { import * as tf from '@tensorflow/tfjs';
                                                                 ^

SyntaxError: Unexpected token *
    at new Script (vm.js:83:7)
    at createScript (vm.js:267:10)
    at Object.runInThisContext (vm.js:319:10)
    at Module._compile (internal/modules/cjs/loader.js:684:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)

I installed tensorflowjs with the flag "-g" because I do not want to create a project and install it there

I have node v11.5.0 and npm v6.4.1

    
asked by ignacio ibarra 21.12.2018 в 23:32
source

1 answer

0

This happens because you are using import * as tf from '@tensorflow/tfjs'; and you probably do not have babel configured to use the import .

try using the following:

const tf = require('@tensorflow/tfjs');

Then use the functions as they appear in the documentation.

    
answered by 25.12.2018 в 04:14