reactjs - 如何解决在尝试 npm i React 项目中的模块时出现的错误

标签 reactjs npm npm-install

在尝试安装某些 npm 时遇到一些问题,我删除了整个 node_modules 文件夹,以便重新安装它,希望它能解决问题。在删除该文件夹之前,我的项目运行良好(只是无法安装新的 npm)。删除后,我现在无法重新安装模块(npm i),因为它在过程中不断给我带来巨大的错误...我还尝试使用我知道的备份 package.json 和 package-lock秩序良好,但它总是给我同样的错误。

如果有人可以提供帮助,我们将不胜感激。

错误:

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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1cfcec5c48cc6d8d1e1968f908f93" rel="noreferrer noopener nofollow">[email protected]</a>
npm ERR! gyp info using <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9d7d6dddcf9888d97888f9789" rel="noreferrer noopener nofollow">[email protected]</a> | 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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0dedfd4d59dd7c9c0f0879e819e82" rel="noreferrer noopener nofollow">[email protected]</a>
    npm ERR! gyp info using <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cca2a3a8a98cfdf8e2fdfbe2fc" rel="noreferrer noopener nofollow">[email protected]</a> | 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

最佳答案

解决方案位于最新的错误消息中(如果您不熟悉要查找的内容,很容易错过):

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 是一个常用的包,它编译(或帮助编译?或其他东西)C/C++ 依赖项。我相信此消息建议安装带有 C++ 安装程序的 Visual Studio 将安装在 Windows 计算机上继续所需的内容。

关于reactjs - 如何解决在尝试 npm i React 项目中的模块时出现的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67620098/

相关文章:

javascript - 为什么即使我有多个目标元素,React.Component 也只渲染一次

reactjs - 将 useRef 钩子(Hook)传递给 ref 属性的正确方法

javascript - Material UI - radio 无法确定我的状态

node.js - 启动npm : npm ERR!代码ELIFECYCLE时遇到此问题

gruntjs - Karma + PhantomJS + 无法访问互联网

javascript - 无法在 Windows 7 中运行全局安装的 Node 模块

ruby-on-rails - 如何避免reactjs被两次包含在rails和reactjs环境中?

javascript - 插件 gulp-babel : Plugin/Preset files are not allowed to export objects, 中的错误仅起作用

javascript - 使用 node-sass 安装 angular-cli 时出错

windows - npm 安装错误 : `gyp` failed with exit code: 1