前端代码运行问题

今天组长分配了一个新任务,让我修改一个已经上线的系统;由于俺只是一个小菜鸟,所以任务并没有很难,只是添加一些细小的功能。

但是…… 当我从 gitee 拉下前端代码运行时,遇到了一个问题,折磨了我好久,如今终于把它解决了,决定把它记录下来,如果能帮助到各位看官,那就再好不过啦!

废话不多说了,详情如下:

首页,按正常的运行步骤,在Visual Studio Code 上运行代码,打开终端,输入:

 npm install

就出现了下面对的问题:

npm ERR! code 1
npm ERR! path D:xxxxxxx\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c C:\xxxxxxx\AppData\Local\Temp\postinstall-7580d09f.cmd
npm ERR! Building: D:\Program Files\nodejs\node.exe D:\xxxxxxx\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'D:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'D:\\xxxxxxx\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.17.1 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:206:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:206:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb could not find "python". checking python launcher
npm ERR! gyp verb could not find "python". guessing location
npm ERR! gyp verb ensuring that file exists: C:\Python27\python.exe
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
xxxxxxx
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:206:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\xxxxxxx\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\xxxxxxx\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.17.1
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\xxxxxxx\AppData\Local\npm-cache\_logs\2022-10-12T02_26_20_477Z-debug-0.log

经过几次的试验,以及网上多次查找解决方法,我得出的结论,发生这个问题的原因就是:node 的版本和 node-sass 的版本不匹配,改动 node-sass 的版本,也待改 sass-loader 的版本。

所以我进行了下面几步操作:

第一步,卸载原来的node-sass,直接安装有冲突

> npm uninstall node-sass

第二步,打包

> npm install
第三步,安装新版本的 node-sass

> npm install node-sass@6.0.1

第四步,安装与新版node-sass匹配的 sass-loader

> npm install sass-loader@10.2.0

最后,运行成功啦!!!
> npm run dev 

另外一种情况比较严重,如题报错如下:

npm ERR! code 1
npm ERR! path XXXXXXXXXXXX/deasync
npm ERR! command failed

如果是这种情况下,目前找到的办法就是:卸载node高版本,安装低版本,如果哪位大神有更好的解决方法,期待您的留言!!!

低版本下载地址

我下载的是压缩包格式的,解压后需要手动在系统变量中配置:

D:\Program Files\nodejs\

D:\Program Files\nodejs\node_global

注意:一般情况下,降到 14 的版本即可,具体需视情况而定!!!

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值