'Getting Error on installing Truffle on windows 10 using npm install truffle -g

When i tried to install truffle i got these errors :-

I have installed Node.js earlier and also i have pip installed.

PS C:\Users\pk199\Documents> npm install -g truffle

npm ERR! code 1
npm ERR! path C:\Users\pk199\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules\leveldown
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.1 found at "C:\Users\pk199\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version was set from command line or npm config
npm ERR! gyp ERR! find VS - looking for Visual Studio version 2022
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Community"
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS valid versions for msvs_version:
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:404:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"   
npm ERR! gyp ERR! cwd C:\Users\pk199\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules\leveldown
npm ERR! gyp ERR! node -v v16.13.1
npm ERR! gyp ERR! node-gyp -v v8.3.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\pk199\AppData\Local\npm-cache\_logs\2022-01-24T15_16_27_276Z-debug.log

I have installed C++ Desktop development in visual studio 2022 as well but still getting this error



Solution 1:[1]

I was able to get truffle installed on Windows 10 by going one version older. Ran PS in Administrator mode (With Execution Policy set to "ByPass"). Hope this helps.

npm install -g [email protected]

PS C:\Windows\system32> npm list -g
C:\Users\*****\AppData\Roaming\npm
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- **[email protected]**
`-- [email protected]


PS C:\Windows\system32> truffle
Truffle v5.4.29 - a development framework for Ethereum

Usage: truffle <command> [options]

Commands:
  build     Execute build pipeline (if configuration present)
  compile   Compile contract source files
  config    Set user-level configuration options
  console   Run a console with contract abstractions and commands available
  create    Helper to create new contracts, migrations and tests
  db        Database interface commands
  debug     Interactively debug any transaction on the blockchain
  deploy    (alias for migrate)
  develop   Open a console with a local development blockchain
  exec      Execute a JS module within this Truffle environment
  help      List all commands or provide information about a specific command
  init      Initialize new and empty Ethereum project
  install   Install a package from the Ethereum Package Registry
  migrate   Run migrations to deploy contracts
  networks  Show addresses for deployed contracts on each network
  obtain    Fetch and cache a specified compiler
  opcode    Print the compiled opcodes for a given contract
  preserve  Save data to decentralized storage platforms like IPFS and Filecoin
  publish   Publish a package to the Ethereum Package Registry
  run       Run a third-party command
  test      Run JavaScript and Solidity tests
  unbox     Download a Truffle Box, a pre-built Truffle project
  version   Show version number and exit
  watch     Watch filesystem for changes and rebuild the project automatically

See more at http://trufflesuite.com/docs

Solution 2:[2]

It's very clear from the error logs that you are missing one of the dependencies i.e. Visual Studio

npm ERR! gyp ERR! find VS could not find a version of Visual Studio 
2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only 

Even the solution is also there in the logs

npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with 
C++" workload.
npm ERR! gyp ERR! find VS For more information consult the 
documentation at:npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows

Steps to install Visual Studio

Step 1: Go to https://visualstudio.microsoft.com/vs/ and install the installer.

There are three editions to choose from

  • Community(free)
  • Professional(paid)
  • Enterprise(paid) enter image description here

Step 2: Run the installer and choose Desktop development with c++ to install

enter image description here

After installation of visual studio, retry truffle installation

Note: If you are using windows, then you have to close the terminal after installation of the visual studio and then open the terminal again with admin rights and retry truffle installation.

Solution 3:[3]

Here are some references that might help:

Try installing Truffle via PowerShell in Admin mode (very important that you're in Admin mode)

You'll need to allow scripts to run as an Admin in PowerShell. To do this, here are some references in the threads in Stack Overflow:

Enable Execution of PowerShell Scripts

PowerShell Scripts

Cannot Install Truffle

I ran the command Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force in PowerShell to get this to work, but please reference the threads above before doing this.

Solution 4:[4]

Before installing nodeJS, you need to make sure dependencies such as python (version 3.10 in my case) are already installed. After many days of trying to fix the error, I just uninstalled nodeJs and reinstalled it. Running the npm install -g truffle command worked.

Solution 5:[5]

for windows try to execute following command

npm install -g [email protected]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 General Grievance
Solution 2
Solution 3
Solution 4 Joseph Joestar
Solution 5 piash tanjin