gpt4 book ai didi

node.js - tensorflow 导入时出现意外标记 *

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:35 24 4
gpt4 key购买 nike

我目前在将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com