【问题标题】:Why do I get errors when importing tfjs-node?为什么在导入 tfjs-node 时会出错?
【发布时间】:2022-08-18 02:41:07
【问题描述】:
import * as tfn from \'@tensorflow/tfjs-node

向我抛出以下警告:

WARNING  Compiled with 4 warnings                                                                                                                                                                 15:06:46  
warning  in ./node_modules/@tensorflow/tfjs-node/dist/index.js    
Critical dependency: the request of a dependency is an expression    
warning  in ./node_modules/@mapbox/node-pre-gyp/lib/util/compile.js   
Module not found: Error: Can\'t resolve \'node-gyp\' in \'C:\\Users\\Username\\Desktop\\Team\\my-app\\node_modules\\@mapbox\\node-pre-gyp\\lib\\util\'   
warning  in ./node_modules/@mapbox/node-pre-gyp/lib/util/compile.js    
Module not found: Error: Can\'t resolve \'npm\' in \'C:\\Users\\Username\\Desktop\\Team\\my-app\\node_modules\\@mapbox\\node-pre-gyp\\lib\\util\'   
warning  in ./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>

这是为什么? (Vue:2.7.8)

Webpack.config.js:

const path = require(\'path\');
const nodeExternals = require(\'webpack-node-externals\');

module.exports = {
  entry: \'./server.js\',
  mode: \'production\',
  target: \'node\',
  externals: [nodeExternals()],
  output: {
    path: path.resolve(__dirname, \'.\'),
    filename: \'server.bundle.js\'
  }
};

软件包版本:

├── @tensorflow/tfjs-converter@3.19.0
├── @tensorflow/tfjs-core@3.19.0
├── @tensorflow/tfjs-node@3.19.0
├── @tensorflow/tfjs@3.19.0
├── aws-sdk@2.1195.0

(如果您需要更多详细信息,请告诉我)

    标签: vuejs2 tensorflow.js


    【解决方案1】:

    根据您的错误,您可能正在使用 Python 3。根据the documentation,“Windows 和 OSX 对 node-gyp 的构建支持需要 Python 2.7”。如果您使用的是正确版本的 Python,请参阅Windows troubleshooting guide 了解更多故障排除信息。

    反之,可以使用Windows Subsystem for Linux,然后通过Linux与TensorFlow.js进行交互。我团队中使用 Windows 的同事更喜欢这种方法,所以我会推荐它。

    【讨论】:

      猜你喜欢
      • 2018-12-25
      • 1970-01-01
      • 2022-11-07
      • 1970-01-01
      • 2021-05-29
      • 2019-07-07
      • 2018-09-21
      • 2020-07-28
      • 1970-01-01
      相关资源
      最近更新 更多