question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to install usb-detection in windows-latest environment

See original GitHub issue

When I run npm install in GitHub Actions windows-latest environment I get following error

npm ERR! D:\a\cs\cs\electron\node_modules\usb-detection\src\detection.h(5,10): fatal error C1083: Cannot open include file: 'node.h': No such file or directory [D:\a\cs\cs\electron\node_modules\usb-detection\build\detection.vcxproj]

Interesting is that each time I run the workflow I get different errors or no errors at all and install succeeds

What’s common is that if install fails it does on node-gyp rebuild command

node-gyp rebuild is called by usb-detection and @serialport/bindings packages in their install scripts

It looks like node-gyp fails to find some files, e.g. node.h, v8.h, common.gypi

It is really hard to debug it since the outcome alters with each run

Any suggestions on what may be a reason of it?

Workflow

release_on_windows:
  runs-on: windows-latest

  steps:
    - uses: actions/checkout@master

    - uses: actions/setup-node@master
      with:
        node-version: 14

    - run: npm install

Dependencies

  "dependencies": {
    "@sentry/electron": "^2.4.1",
    "electron-updater": "^4.3.9",
    "electron-window-state": "^5.0.3",
    "serialport": "^9.0.7",
    "usb-detection": "^4.10.0"
  },
  "devDependencies": {
    "@sentry/cli": "^1.65.0",
    "cross-env": "^7.0.3",
    "electron": "^12.0.9",
    "electron-builder": "^22.9.1",
    "electron-download": "^4.1.1"
  }

Error examples

npm ERR! C:\Users\runneradmin\.electron-gyp\12.0.9\include\node\node.h(67,10): fatal error C1083: Cannot open include file: 'v8.h': No such file or directory [D:\a\cs\cs\electron\node_modules\usb-detection\build\detection.vcxproj]
npm ERR! gyp: C:\Users\runneradmin\AppData\Local\node-gyp\Cache\14.17.1\common.gypi not found (cwd: D:\a\cs\cs\electron\node_modules\usb-detection) while reading includes of binding.gyp while trying to load binding.gyp
npm ERR! gyp: C:\Users\runneradmin\.electron-gyp\12.0.9\common.gypi not found (cwd: D:\a\cs\cs\electron\node_modules\@serialport\bindings) while reading includes of binding.gyp while trying to load binding.gyp

Log example

Run npm install
  npm install
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

> swimcloud-meet@0.1.6 postinstall
> electron-builder install-app-deps

  • electron-builder  version=22.10.5
  • loaded configuration  file=package.json ("build" field)
  • rebuilding native dependencies  dependencies=@serialport/bindings@9.0.7, usb-detection@4.10.0 platform=win32 arch=x64
  • install prebuilt binary  name=@serialport/bindings version=9.0.7 platform=win32 arch=x64
  • build native dependency from sources  name=@serialport/bindings
                                          version=9.0.7
                                          platform=win32
                                          arch=x64
                                          reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
                                          error=prebuild-install info begin Prebuild-install version 6.1.2
    prebuild-install WARN install prebuilt binaries enforced with --force!
    prebuild-install WARN install prebuilt binaries may be out of date!
    prebuild-install info looking for local prebuild @ prebuilds\bindings-v9.0.7-electron-v87-win32-x64.tar.gz
    prebuild-install info looking for cached prebuild @ C:\npm\cache\_prebuilds\e02868-bindings-v9.0.7-electron-v87-win32-x64.tar.gz
    prebuild-install http request GET https://github.com/serialport/node-serialport/releases/download/@serialport/bindings@9.0.7/bindings-v9.0.7-electron-v87-win32-x64.tar.gz
    prebuild-install http 404 https://github.com/serialport/node-serialport/releases/download/@serialport/bindings@9.0.7/bindings-v9.0.7-electron-v87-win32-x64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=12.0.9 runtime=electron arch=x64 libc= platform=win32)
    
  • install prebuilt binary  name=usb-detection version=4.10.0 platform=win32 arch=x64
  • build native dependency from sources  name=usb-detection
                                          version=4.10.0
                                          platform=win32
                                          arch=x64
                                          reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
                                          error=prebuild-install info begin Prebuild-install version 6.1.2
    prebuild-install WARN install prebuilt binaries enforced with --force!
    prebuild-install WARN install prebuilt binaries may be out of date!
    prebuild-install info looking for local prebuild @ prebuilds\usb-detection-v4.10.0-electron-v87-win32-x64.tar.gz
    prebuild-install info looking for cached prebuild @ C:\npm\cache\_prebuilds\bd48fa-usb-detection-v4.10.0-electron-v87-win32-x64.tar.gz
    prebuild-install http request GET https://github.com/MadLittleMods/node-usb-detection/releases/download/v4.10.0/usb-detection-v4.10.0-electron-v87-win32-x64.tar.gz
    prebuild-install http 404 https://github.com/MadLittleMods/node-usb-detection/releases/download/v4.10.0/usb-detection-v4.10.0-electron-v87-win32-x64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=12.0.9 runtime=electron arch=x64 libc= platform=win32)
    
  ⨯ cannot execute  cause=exit status 1
                    errorOut=npm ERR! code 1
    npm ERR! path D:\a\cs\cs\electron\node_modules\usb-detection
    npm ERR! command failed
    npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install || node-gyp rebuild
    npm ERR! Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
    npm ERR!   detection.cpp
    npm ERR! D:\a\cs\cs\electron\node_modules\usb-detection\src\detection.h(5,10): fatal error C1083: Cannot open include file: 'node.h': No such file or directory [D:\a\cs\cs\electron\node_modules\usb-detection\build\detection.vcxproj]
    npm ERR! gyp info it worked if it ends with ok
    npm ERR! gyp info using node-gyp@7.1.2
    npm ERR! gyp info using node@14.17.1 | win32 | x64
    npm ERR! gyp info find Python using Python version 3.7.9 found at "C:\hostedtoolcache\windows\Python\3.7.9\x64\python3.exe"
    npm ERR! gyp http GET https://electronjs.org/headers/v12.0.9/node-v12.0.9-headers.tar.gz
    npm ERR! gyp http 200 https://electronjs.org/headers/v12.0.9/node-v12.0.9-headers.tar.gz
    npm ERR! gyp http GET https://electronjs.org/headers/v12.0.9/SHASUMS256.txt
    npm ERR! gyp http GET https://electronjs.org/headers/v12.0.9/win-x86/node.lib
    npm ERR! gyp http GET https://electronjs.org/headers/v12.0.9/win-x64/node.lib
    npm ERR! gyp http GET https://electronjs.org/headers/v12.0.9/win-arm64/node.lib
    npm ERR! gyp http 200 https://electronjs.org/headers/v12.0.9/SHASUMS256.txt
    npm ERR! gyp http 200 https://electronjs.org/headers/v12.0.9/win-x86/node.lib
    npm ERR! gyp http 200 https://electronjs.org/headers/v12.0.9/win-x64/node.lib
    npm ERR! gyp http 200 https://electronjs.org/headers/v12.0.9/win-arm64/node.lib
    npm ERR! gyp info find VS using VS2019 (16.10.31410.357) found at:
    npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
    npm ERR! gyp info find VS run with --verbose for detailed information
    npm ERR! gyp info spawn C:\hostedtoolcache\windows\Python\3.7.9\x64\python3.exe
    npm ERR! gyp info spawn args [
    npm ERR! gyp info spawn args   'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
    npm ERR! gyp info spawn args   'binding.gyp',
    npm ERR! gyp info spawn args   '-f',
    npm ERR! gyp info spawn args   'msvs',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   'D:\\a\\cs\\cs\\electron\\node_modules\\usb-detection\\build\\config.gypi',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   'C:\\Users\\runneradmin\\.electron-gyp\\12.0.9\\include\\node\\common.gypi',
    npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
    npm ERR! gyp info spawn args   '-Dvisibility=default',
    npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\\Users\\runneradmin\\.electron-gyp\\12.0.9',
    npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp',
    npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\runneradmin\\\\.electron-gyp\\\\12.0.9\\\\<(target_arch)\\\\node.lib',
    npm ERR! gyp info spawn args   '-Dmodule_root_dir=D:\\a\\cs\\cs\\electron\\node_modules\\usb-detection',
    npm ERR! gyp info spawn args   '-Dnode_engine=v8',
    npm ERR! gyp info spawn args   '--depth=.',
    npm ERR! gyp info spawn args   '--no-parallel',
    npm ERR! gyp info spawn args   '--generator-output',
    npm ERR! gyp info spawn args   'D:\\a\\cs\\cs\\electron\\node_modules\\usb-detection\\build',
    npm ERR! gyp info spawn args   '-Goutput_dir=.'
    npm ERR! gyp info spawn args ]
    npm ERR! gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
    npm ERR! gyp info spawn args [
    npm ERR! gyp info spawn args   'build/binding.sln',
    npm ERR! gyp info spawn args   '/clp:Verbosity=minimal',
    npm ERR! gyp info spawn args   '/nologo',
    npm ERR! gyp info spawn args   '/p:Configuration=Release;Platform=x64'
    npm ERR! gyp info spawn args ]
    npm ERR! gyp ERR! build error 
    npm ERR! gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
    npm ERR! gyp ERR! stack     at ChildProcess.onExit (C:\npm\prefix\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
    npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:375:28)
    npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
    npm ERR! gyp ERR! System Windows_NT 10.0.17763
    npm ERR! gyp ERR! command "C:\\hostedtoolcache\\windows\\node\\14.17.1\\x64\\node.exe" "C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    npm ERR! gyp ERR! cwd D:\a\cs\cs\electron\node_modules\usb-detection
    npm ERR! gyp ERR! node -v v14.17.1
    npm ERR! gyp ERR! node-gyp -v v7.1.2
    npm ERR! gyp ERR! not ok
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\npm\cache\_logs\2021-06-25T13_32_38_595Z-debug.log
    
                    command='C:\hostedtoolcache\windows\node\14.17.1\x64\node.exe' 'C:\npm\prefix\node_modules\npm\bin\npm-cli.js' rebuild @serialport/bindings@9.0.7 usb-detection@4.10.0
                    workingDir=
npm ERR! code 1
npm ERR! path D:\a\cs\cs\electron
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c electron-builder install-app-deps

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2021-06-25T13_32_38_662Z-debug.log
Error: Process completed with exit code 1.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
IvanZosimovcommented, May 27, 2022

Hi, @kiruh 👋 ! The root cause of your problem is in the version of the node-gyp. The thing is that the version which is bundled in npm is too outdated (in your case it’s v5.1.0). Such an old version simply doesn’t support VS2022, which is the only version of the VS installed on the windows-latest image. This problem is met very often by customers of the node-gyp, so the maintainers of the node-gyp created a special manual describing how to update its version. Below you can find the workaround which was created with reference to the manual I mentioned above:

- name: Update node-gyp
   run: |
     $WhereNode = Get-Command node | Select-Object -ExpandProperty Definition
     $NodeDirPath = Split-Path $WhereNode -Parent
     $NodeModulesPath = $NodeDirPath + "\node_modules\npm\node_modules\npm-lifecycle"
     cd $NodeModulesPath
     npm install node-gyp@8.x

Could you, please, ping me if everything is OK?

1reaction
kiruhcommented, May 27, 2022

Hi @IvanZosimov,

Yes, it works!

Thank you 🎉


Final Result

workflow.yml

name: Workflow

on: workflow_dispatch

jobs:
  release_on_windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@master

      - uses: actions/setup-node@master
        with:
          node-version: 14

      - name: Update node-gyp
        run: |
          $WhereNode = Get-Command node | Select-Object -ExpandProperty Definition
          $NodeDirPath = Split-Path $WhereNode -Parent
          $NodeModulesPath = $NodeDirPath + "\node_modules\npm\node_modules\npm-lifecycle"
          cd $NodeModulesPath
          npm install node-gyp@8.x

      - name: Install dependencies
        run: npm install
Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to install usb-detection in windows-latest environment
When I run npm install in GitHub Actions windows-latest environment I get following error npm ERR!
Read more >
How to Fix USB Device Not Recognized on Windows 11/10/8/7
In this article, we explain how to fix the USB device not recognized Windows 11/10/8/7 error to help you regain access to important...
Read more >
"USB Device not recognized" error - Windows Server
"USB Device not recognized" error when you try to access a USB external hard drive · Symptoms · Cause · Resolution 1 -...
Read more >
How to Fix the "Failed to Attach the USB Device" Error in ...
Launch File Explorer on your Windows system. · Navigate to the Device subfolder and find the VBoxUSB. · Right-click on the file and...
Read more >
How to fix USB device not recognized or USB not Installed ...
1. First download the Microsoft Fix It utility to your computer.* · 2. Run Microsoft Fix It tool and press “Accept”. · 3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found