node.js - TypeError:“原始”参数必须是函数类型
问题描述
尝试在我的电子反应应用程序中要求 tfjs-node 时出现此错误。这个问题在我没有安装 react 之前没有发生,我认为这是由于 webpack 需要配置中的某些内容。
const tf = require('@tensorflow/tfjs-node');
错误日志:
Uncaught TypeError: The "original" argument must be of type Function
at Object.promisify (util.js:601)
at Object.<anonymous> (file_system.js:58)
at Object../node_modules/@tensorflow/tfjs-node/dist/io/file_system.js (file_system.js:359)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Object../node_modules/@tensorflow/tfjs-node/dist/index.js (index.js:34)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Object../src/components/ssd/image_utils.js (image_utils.js:2)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Object.<anonymous> (ssd.js:1)
at Object../src/components/ssd/ssd.js (ssd.js:196)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Object../src/components/recorder/screen_utils.js (screen_utils.js:5)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Module../src/components/recorder/Recorder.js (Recorder.css?0341:45)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Module../src/Router.js (index.css:7)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Module../src/index.js (index.css?f3f6:45)
at __webpack_require__ (bootstrap:785)
at fn (bootstrap:150)
at Object.1 (serviceWorker.js:141)
at __webpack_require__ (bootstrap:785)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
我是 webpack 的新手,非常感谢任何帮助,并且很乐意回答任何需要的澄清,因为我不知道问题的根源要更详细。
包.json:
"dependencies": {
"@tensorflow/tfjs-node": "^1.6.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"aws-sdk": "^2.635.0",
"electron": "^8.1.0",
"electron-is-dev": "^1.1.0",
"electron-log": "^4.0.7",
"fs": "0.0.1-security",
"jimp": "^0.9.5",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.0",
"robotjs": "^0.6.0",
"util.promisify": "^1.0.1"
},
解决方案
问题在于需求。“@tensorflow/tfjs-node” 导出多个东西(可能),所以这个模块内的导出类似于
module.exports = {
firstThing,
secondThing, ...
}
因此,代码中的 tf 是一个对象,而不是一个函数。所以,你应该像这样使用命名导入,
const {tf} = require('@tensorflow/tfjs-node')
因此,您在调用 tf. 我没有使用过这个包,但这似乎是错误的原因。如果它不能解决问题,请添加引发错误的行。
推荐阅读
- angular - 如何在 Angular 中从服务中填充列表数据
- sql - Skip Update of Table when no records present-SQL
- javascript - Javascript 在请求中不包括表单数据
- android - sqlite 按包含带逗号分隔符的数字的字符串排序
- php - 带有外部应用程序的 Symfony PdoSessionHandler
- python - 在 Python 中查找字典值的最小值
- intellij-idea - 是否可以创建 IntelliJ(不是正在开发的程序)本机的常量以在“评估表达式”对话框中使用?
- c# - 如何以编程方式确定 Click-Once 应用程序的 exe 位置
- javascript - 使用打字稿中的动态值进行过滤
- javascript - 如何向我的定制 Javascript 界面添加可选属性?