TypeError: The "original" argument must be of type Function

Viewed 8138

I am getting this error when trying to require tfjs-node in my electron react application. This issue wasn't happening before when I did not have react installed and I think it is due to something in the webpack require configuration.

const tf = require('@tensorflow/tfjs-node');

Error Log:

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

I am new to webpack and would appreciate any help and am happy to answer any clarifications needed as I do not know the source of the problem to be more detailed.

Package.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"
  },
1 Answers

The issue is with the require. "@tensorflow/tfjs-node" exports multiple things(possibly), so the export inside this module would be something like

module.exports = {
    firstThing,
    secondThing, ...
}

So, tf in your code is an object, and not a function. So, you should use named import like this,

const {tf} = require('@tensorflow/tfjs-node')

So, you are getting an error when invoking tf. I have not worked with this package, but this seems like the cause for error. If it doesn't fix the issue, please add the line that is throwing the error.

Related