tfjs: Error when trying to use tfjs-node on Windows 10

In my main.mjs file I have import * as tf from "@tensorflow/tfjs-node";.

I get this error when I try to run the file:

node:internal/modules/cjs/loader:1142
  return process.dlopen(module, path.toNamespacedPath(filename));
                ^

Error: The specified module could not be found.
\\?\D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node\lib\napi-v6\tfjs_binding.node
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1142:18)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14)
    at Module.require (node:internal/modules/cjs/loader:972:19)
    at require (node:internal/modules/cjs/helpers:88:18)
    at Object.<anonymous> (D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node\dist\index.js:58:16)
    at Module._compile (node:internal/modules/cjs/loader:1083:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14) {
  code: 'ERR_DLOPEN_FAILED'
}

Here’s the output of node-gyp configure --verbose:

gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'D:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'D:\\Program Files\\nodejs\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'configure',
gyp verb cli   '--verbose'
gyp verb cli ]
gyp info using node-gyp@7.1.2
gyp info using node@15.0.1 | win32 | x64
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON      
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - "python3" is not in PATH or produced an error
gyp verb find Python checking if "python" can be used
gyp verb find Python - executing "python" to get executable path    
gyp verb find Python - executable path is "D:\Python27\python.exe"      
gyp verb find Python - executing "D:\Python27\python.exe" to get version
gyp verb find Python - version is "2.7.18"
gyp info find Python using Python version 2.7.18 found at "D:\Python27\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 15.0.1
gyp verb command install [ '15.0.1' ]
gyp verb install input version string "15.0.1"
gyp verb install installing version: 15.0.1   
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 15.0.1
gyp verb build dir attempting to create "build" dir: D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node\build
gyp verb build dir "build" dir needed to be created? undefined
gyp verb find VS msvs_version not set from command line or npm config
gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp verb find VS checking VS2019 (16.7.30621.155) found at:
gyp verb find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
gyp verb find VS - found "Visual Studio C++ core features"
gyp verb find VS - found VC++ toolset: v142
gyp verb find VS - found Windows SDK: 10.0.18362.0
gyp info find VS using VS2019 (16.7.30621.155) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
gyp info find VS run with --verbose for detailed information
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node\build\config.gypi
gyp verb config.gypi checking for gypi file: D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node\config.gypi
gyp verb common.gypi checking for gypi file: D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn D:\Python27\python.exe
gyp info spawn args [
gyp info spawn args   'D:\\Users\\fried\\AppData\\Roaming\\nvm\\v15.0.1\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\Users\\fried\\Documents\\VSCode Projects\\Ai+ML\\Mountain Car\\node_modules\\@tensorflow\\tfjs-node\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\Users\\fried\\AppData\\Roaming\\nvm\\v15.0.1\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\fried\\AppData\\Local\\node-gyp\\Cache\\15.0.1\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\fried\\AppData\\Local\\node-gyp\\Cache\\15.0.1',
gyp info spawn args   '-Dnode_gyp_dir=D:\\Users\\fried\\AppData\\Roaming\\nvm\\v15.0.1\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\fried\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\15.0.1\\\\<(target_arch)\\\\node.lib', 
gyp info spawn args   '-Dmodule_root_dir=D:\\Users\\fried\\Documents\\VSCode Projects\\Ai+ML\\Mountain Car\\node_modules\\@tensorflow\\tfjs-node',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'D:\\Users\\fried\\Documents\\VSCode Projects\\Ai+ML\\Mountain Car\\node_modules\\@tensorflow\\tfjs-node\\build',        
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (D:\Users\fried\AppData\Roaming\nvm\v15.0.1\node_modules\node-gyp\lib\configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (node:events:327:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:277:12)
gyp ERR! System Windows_NT 10.0.19041
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--verbose"
gyp ERR! cwd D:\Users\fried\Documents\VSCode Projects\Ai+ML\Mountain Car\node_modules\@tensorflow\tfjs-node
gyp ERR! node -v v15.0.1
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok

As you can see from the log I made sure that it was using Python 2 instead of Python 3, but it still isn’t working. I’ve tried following the instructions here as well, but to no avail.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Why does this get closed again? The issue is still persisting on multiple platforms and node versions.

It kind of worked! So first, I installed node-pre-gyp globally, and then I ran node-pre-gyp rebuild in node_modules/@tensorflow/tfjs-node. I still got the same error when running node main.mjs. Then, I copied tensorflow.dll and tensorflow.lib from deps/lib to lib/napi-v6. Now I am getting this error:

tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not 
compiled to use: AVX2

After about a day of research I stumbled across this thread (finally!). Turns out @Jwiggiff 's response worked for me as well:

RUN npm i -g node-pre-gyp && \
    cd /usr/src/app/node_modules/@tensorflow/tfjs-node && node-pre-gyp rebuild && \
    cp /usr/src/app/node_modules/@tensorflow/tfjs-node/deps/lib/* /usr/src/app/node_modules/@tensorflow/tfjs-node/lib/napi-v8/

As @jeanbmar has stated, however, I don’t think this issue should be closed. The above was the only thing that worked across several different versions node images (Docker).

@Jwiggiff, @rthadur the issue shouldn’t be closed on a workaround involving to manually move files from node_modules subdirectories.

There’s a problem with Node.js N-api that should be fixed on Windows because many other users will get it soon.

The install script stops at napi v6 while recent Node.js versions use napi v7 (https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix).

dll file isn’t linked properly because cp.exec('node scripts/deps-stage.js symlink ' + modulePath); in install.js generates running node scripts/deps-stage.js symlink ./lib/napi-v7 while tfjs_binding.node is stored in lib/napi-v6.

I think this is not related to windows because I see this issue on

I tried npm rebuild @tensorflow/tfjs-node build-addon-from-source with no luck.

UPDATE:

Seems like the issue was the white space in the project path. Something like /MyFolder/My Name/ always failed.

It’s a warrning. Computation should work despite it

  1. module_name problem solves with other runner, use node-pre-gyp rebuild
  2. You shoul manualy past files to node_modules/@tensorflow/tfjs-node/lib/napi-v6. Copy it from deps/lib

After about a day of research I stumbled across this thread (finally!). Turns out @Jwiggiff 's response worked for me as well:

RUN npm i -g node-pre-gyp && \
    cd /usr/src/app/node_modules/@tensorflow/tfjs-node && node-pre-gyp rebuild && \
    cp /usr/src/app/node_modules/@tensorflow/tfjs-node/deps/lib/* /usr/src/app/node_modules/@tensorflow/tfjs-node/lib/napi-v8/

As @jeanbmar has stated, however, I don’t think this issue should be closed. The above was the only thing that worked across several different versions node images (Docker).

Thank you, I was stuck here for 4 days It is working on my device Node : v20.11.0 npm : 10.4.0 tfjs-node: ^4.17.0 windows: 11

I have a similar error when trying to install TFJS/Node. I’ve been reading articles and installing packages (node-gyp , python 3.10 and node-pre-gyp) for 4 hours now but still nothing. Someone should’ve told me installing will be this difficult. Damn youtube videos, making it so easy with their npm install tensorfrow/tfjs-nodes.

I tried @MountainAndMorning 's solution but my directory ends at \node_modules\@tensorflow\tfjs-node, no \lib\napi-vx.

image

Ive tried literally every suggestion i can find, even this from here no avail. Still getting this error.

PS D:\Projects\art-review-bot\node_modules\@tensorflow\tfjs-node> node-gyp configure --verbose
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'C:\\Users\\Thierry_Ntoh\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'configure',
gyp verb cli   '--verbose'
gyp verb cli ]
gyp info using node-gyp@8.4.1
gyp info using node@16.13.1 | win32 | x64
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - "python3" is not in PATH or produced an error
gyp verb find Python checking if "python" can be used
gyp verb find Python - executing "python" to get executable path
gyp verb find Python - executable path is "C:\Users\Thierry_Ntoh\AppData\Local\Programs\Python\Python310\python.exe"
gyp verb find Python - executing "C:\Users\Thierry_Ntoh\AppData\Local\Programs\Python\Python310\python.exe" to get version
gyp verb find Python - version is "3.10.2"
gyp info find Python using Python version 3.10.2 found at "C:\Users\Thierry_Ntoh\AppData\Local\Programs\Python\Python310\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 
16.13.1
gyp verb command install [ '16.13.1' ]
gyp verb install input version string "16.13.1"
gyp verb install installing version: 16.13.1
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 16.13.1
gyp verb build dir attempting to create "build" dir: D:\Projects\art-review-bot\node_modules\@tensorflow\tfjs-node\build
gyp verb build dir "build" dir needed to be created? No
gyp verb find VS msvs_version not set from command line or npm config
gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
gyp verb find VS looking for Visual Studio 2015
gyp verb find VS - not found
gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
gyp ERR! stack     at C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16     
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
gyp ERR! stack     at C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14     
gyp ERR! stack     at C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:16    
gyp ERR! stack     at C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Users\Thierry_Ntoh\AppData\Roaming\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:404:5)
gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Thierry_Ntoh\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--verbose"
gyp ERR! cwd D:\Projects\art-review-bot\node_modules\@tensorflow\tfjs-node
gyp ERR! node -v v16.13.1
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok

It kinda seems like it requires Visual Studio and i just can’t anymore. I’m just giving up at this point.