微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 React 项目中尝试 npm i 模块时如何解决错误

如何解决在 React 项目中尝试 npm i 模块时如何解决错误

在尝试安装一些 npm 时遇到一些问题,我删除了整个 node_modules 文件夹,以便重新安装它,希望它能解决问题。在删除文件夹之前,我的项目运行良好(只是无法安装新的 npms)。删除后,我现在无法重新安装模块(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 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

解决方法

安装最新版本的 python 和 node.js,并确保它们在您的系统 PATH 中定义。如果错误仍然存​​在,请发布显示的内容。

,

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

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 计算机上继续所需的内容。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。