【问题标题】:Unexpected token * with tensorflow import带有 tensorflow 导入的意外令牌 *
【发布时间】:2019-07-02 15:38:49
【问题描述】:

我目前在将 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很好地识别。

感谢您的帮助。

【问题讨论】:

    标签: node.js tensorflow import unexpected-token


    【解决方案1】:

    代码 sn-p 使用 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
    

    【讨论】:

      【解决方案2】:

      Node 不支持开箱即用的导入/导出或 ES6 模块。

      您需要将文件保存为.mjs 而不是.js 并以:

      node  --experimental-modules  index.mjs
      

      此外,您可以使用 babel 将代码转换为 ES5 并使用它。

      【讨论】:

        猜你喜欢
        • 2018-05-23
        • 2016-06-18
        • 1970-01-01
        • 2019-03-21
        • 2020-03-16
        • 2020-05-07
        • 1970-01-01
        • 2017-07-01
        • 2014-10-24
        相关资源
        最近更新 更多