How to solve an error while trying to npm i the modules in a React project

Viewed 1239

Following some problems when trying to install some npms, I've deleted the entire node_modules folder in order to re-install it with the hope that it would fix the problem. Prior to the deletion of the folder, my project worked fine (just couldn't install new npms). Following the deletion, I'm now unable to reinstall the modules (npm i) as it keeps giving me a huge error in the process... I've also tried to use a backup package.json and package-lock that I know are in good order but it keeps giving me the same errors all the time.

Would appreciate if someone could assist.

The error:

npm ERR! code 1
npm ERR! path C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-sass
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 node-gyp@7.1.2
npm ERR! gyp info using node@14.16.0 | win32 | x64
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
npm ERR! gyp ERR! find Python checking if "python3" can be used
npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if "python" can be used
npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if "python2" can be used
npm ERR! gyp ERR! find Python - "python2" is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if Python is C:\Python37\python.exe
npm ERR! gyp ERR! find Python - "C:\Python37\python.exe" could not be run
npm ERR! gyp ERR! find Python checking if Python is C:\Python27\python.exe 
npm ERR! gyp ERR! find Python - "C:\Python27\python.exe" could not be run  
npm ERR! gyp ERR! find Python checking if the py launcher can be used to find Python
npm ERR! gyp ERR! find Python - "py.exe" is not in PATH or produced an error
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python You need to install the latest version of Python.
npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
npm ERR! gyp ERR! find Python you can try one of the following options:    
npm ERR! gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
npm ERR! gyp ERR! find Python   (accepted by both node-gyp and npm)        
npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
npm ERR! gyp ERR! find Python - Set the npm configuration variable python: 
npm ERR! gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
npm ERR! gyp ERR! find Python For more information consult the documentation at:
npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
npm ERR! gyp ERR! stack     at PythonFinder.fail (C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-python.js:302:47)npm ERR! gyp ERR! stack     at PythonFinder.runChecks (C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-python.js:136:21)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-python.js:200:18)
npm ERR! gyp ERR! stack     at PythonFinder.execFileCallback (C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-python.js:266:16)
npm ERR! gyp ERR! stack     at exithandler (child_process.js:315:5)        
npm ERR! gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:327:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:315:20)        
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
npm ERR! gyp ERR! stack     at onErrorNT (internal/child_process.js:465:16)npm ERR! gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:80:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\\nodejs\\node.exe" "C:\\Users\\Dana\\Desktop\\dev\\airbnb-mock-proj\\frontend\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-sass
npm ERR! gyp ERR! node -v v14.16.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok ```


Following the recommendation, I've reinstalled node and Python (though I'm not completely sure how Python is related as my project is pure js and React) and now I've got some more problems- in addition, it tells me that I should update vscode, which I did but it still gives me the below error:

    npm ERR! code 1
    npm ERR! path C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-sass
    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 node-gyp@7.1.2
    npm ERR! gyp info using node@14.17.0 | win32 | x64
    npm ERR! gyp info find Python using Python version 3.9.5 found at "C:\Users\Dana\AppData\Local\Programs\Python\Python39\python.exe"
    npm ERR! gyp ERR! find VS
    npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
    npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
    npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
    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 **************************************************************
    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:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
    npm ERR! gyp ERR! stack     at C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-visualstudio.js:74:16
    npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
    npm ERR! gyp ERR! stack     at C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-visualstudio.js:70:14
    npm ERR! gyp ERR! stack     at C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\find-visualstudio.js:372:16
    npm ERR! gyp ERR! stack     at C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\util.js:54:7
    npm ERR! gyp ERR! stack     at C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-gyp\lib\util.js:33:16
    npm ERR! gyp ERR! stack     at ChildProcess.exithandler (child_process.js:326:5)
    npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:376:20)
    npm ERR! gyp ERR! stack     at maybeClose (internal/child_process.js:1055:16)
    npm ERR! gyp ERR! System Windows_NT 10.0.19042
    npm ERR! gyp ERR! command "C:\\nodejs\\node.exe" "C:\\Users\\Dana\\Desktop\\dev\\airbnb-mock-proj\\frontend\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    npm ERR! gyp ERR! cwd C:\Users\Dana\Desktop\dev\airbnb-mock-proj\frontend\node_modules\node-sass
    npm ERR! gyp ERR! node -v v14.17.0
    npm ERR! gyp enter code hereERR! node-gyp -v v7.1.2
    npm ERR! gyp ERR! not ok
2 Answers

The solution is in the latest error message (easy to miss if you're not familiar with what to look for):

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 **************************************************************

node-gyp is a commonly used package, which compiles (or helps with compiling? or something) C/C++ dependencies. I believe this message's recommendation to install Visual Studio with the C++ setup will install what it needs to continue on your Windows computer.

install the latest version of python and node.js, and make sure they are defined in your system PATH. If the error still persists post what it shows.

Related