我目前在将 Tensorflow 导入我的项目时遇到问题。
我正在尝试让这段代码工作: https://gist.github.com/learncodeacademy/a96d80a29538c7625652493c2407b6be
但是,当我使用以下命令运行它时:
node iris-tensorflow-js.js.js
我遇到这个错误:
(function (exports, require, module, __filename, __dirname) { import * as tf from "@tensorflow/tfjs/dist/index"
^
SyntaxError: Unexpected token *
奇怪的是,WebStorm 很好地识别了导入。
感谢您的帮助。
最佳答案
该代码片段使用 ECMAScript 模块导入(import
而不是 require()
),Node.js 默认情况下尚不允许这样做。您可以尝试以下两件事:
使用标志启动 Node.js
node --experimental-modules iris-tensorflow-js.js
请注意,您可能必须 rename the file to end in .mjs
.
使用esm
模块
npm install --save esm
node -r esm iris-tensorflow-js
关于node.js - tensorflow 导入时出现意外标记 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56855914/