项目场景:
本人已提前安装了nodejs,且此文仅描述本人所遇问题及解决方案。有类似问题的朋友,此文提供的解决方案仅供参考。
HBuilder X 导入项目,npm install安装依赖,npm run build构建项目时均出现问题。
问题描述及解决
1、执行npm install
命令时报错
5350 error code 1
5351 error path D:项目路径\node_modules\node-sass
5352 error command failed
5353 error command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
5354 error Building: D:\Software Programs\nodejs\node.exe D:项目路径\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
5355 error gyp info it worked if it ends with ok
5355 error gyp verb cli [
5355 error gyp verb cli 'D:\\Software Programs\\nodejs\\node.exe',
5355 error gyp verb cli 'D:项目路径\\node_modules\\node-gyp\\bin\\node-gyp.js',
5355 error gyp verb cli 'rebuild',
5355 error gyp verb cli '--verbose',
5355 error gyp verb cli '--libsass_ext=',
5355 error gyp verb cli '--libsass_cflags=',
5355 error gyp verb cli '--libsass_ldflags=',
5355 error gyp verb cli '--libsass_library='
5355 error gyp verb cli ]
5355 error gyp info using node-gyp@3.8.0
5355 error gyp info using node@16.14.2 | win32 | x64
5355 error gyp verb command rebuild []
5355 error gyp verb command clean []
5355 error gyp verb clean removing "build" directory
5355 error gyp verb command configure []
5355 error gyp verb check python checking for Python executable "python2.7" in the PATH
5355 error gyp verb `which` failed Error: not found: python2.7
5355 error gyp verb `which` failed at getNotFoundError (D:项目路径\node_modules\which\which.js:13:12)
5355 error gyp verb `which` failed at F (D:项目路径\node_modules\which\which.js:68:19)
5355 error gyp verb `which` failed at E (D:项目路径\node_modules\which\which.js:80:29)
5355 error gyp verb `which` failed at D:项目路径\node_modules\which\which.js:89:16
5355 error gyp verb `which` failed at D:项目路径\node_modules\isexe\index.js:42:5
5355 error gyp verb `which` failed at D:项目路径\node_modules\isexe\windows.js:36:5
5355 error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21)
5355 error gyp verb `which` failed python2.7 Error: not found: python2.7
5355 error gyp verb `which` failed at getNotFoundError (D:项目路径\node_modules\which\which.js:13:12)
5355 error gyp verb `which` failed at F (D:项目路径\node_modules\which\which.js:68:19)
5355 error gyp verb `which` failed at E (D:项目路径\node_modules\which\which.js:80:29)
5355 error gyp verb `which` failed at D:项目路径\node_modules\which\which.js:89:16
5355 error gyp verb `which` failed at D:项目路径\node_modules\isexe\index.js:42:5
5355 error gyp verb `which` failed at D:项目路径\node_modules\isexe\windows.js:36:5
5355 error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) {
5355 error gyp verb `which` failed code: 'ENOENT'
5355 error gyp verb `which` failed }
5355 error gyp verb could not find "python2.7". checking python launcher
5355 error gyp verb could not find "python2.7". guessing location
5355 error gyp verb ensuring that file exists: C:\Python27\python.exe
5355 error gyp ERR! configure error
5355 error gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
5355 error gyp ERR! stack at PythonFinder.failNoPython (D:项目路径\node_modules\node-gyp\lib\configure.js:484:19)
5355 error gyp ERR! stack at PythonFinder.<anonymous> (D:项目路径\node_modules\node-gyp\lib\configure.js:509:16)
5355 error gyp ERR! stack at callback (D:项目路径\node_modules\graceful-fs\polyfills.js:295:20)
5355 error gyp ERR! stack at FSReqCallback.oncomplete (node:fs:198:21)
5355 error gyp ERR! System Windows_NT 10.0.22000
5355 error gyp ERR! command "D:\\Software Programs\\nodejs\\node.exe" "D:项目路径\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
5355 error gyp ERR! cwd D:项目路径\node_modules\node-sass
5355 error gyp ERR! node -v v16.14.2
5355 error gyp ERR! node-gyp -v v3.8.0
5355 error gyp ERR! not ok
5355 error Build failed with error code: 1
原本报错好像不是这个,但大体都一样。在这里要讲的是检查node版本与npm版本是否对应。点击查看node与npm版本对应情况。
查看版本:node -v
,npm -v
如果版本不对应那么最好调整。例如:本人node版本为v16.14.2,而npm版本为8.5.5,那么我就得把npm降级。
对应指令:npm install npm@8.5.0
多次执行npm install
,发现每次都是在出现warn后短暂停留了一会儿就出问题。
5274 warn deprecated core-js@2.6.11: core-js@<3.4 is no longer
maintained and not recommended for usage due to the number of issues.
Because of the V8 engine whims, feature detection in old core-js
versions could cause a slowdown up to 100x even if nothing is
polyfilled. Please, upgrade your dependencies to the actual version
of core-js.
找到一篇博客参考,本人是直接安装cnpm。
指令:npm install -g cnpm --registry=https://registry.npm.taobao.org
安装好后直接执行cnpm install
命令安装依赖,最终成功了(可能还是有警告,不管了),项目目录下面有node_modules目录了
2、随后我就执行npm run build
命令构建项目,结果出现以下错误提示
ERROR in ./node_modules/_css-loader@0.28.11@css-loader!./node_modules/_vue-loader@13.7.3@vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-279e0a52","scoped":false,"hasInlineConfig":false}!./node_modules/_sass-loader@6.0.7@sass-loader/lib/loader.js!./node_modules/_vue-loader@13.7.3@vue-loader/lib/selector.js?type=styles&index=0!./src/view/doctorManagement/components/doctorOption.vue
Module build failed: Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
经分析Error:Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)可知当前node_sass版本不支持当前系统环境。根据提示我们去查看版本支持情况。
根据上面的对应关系,我的系统为Windows64位操作系统,node为v16.14.2版本,所以对应的node-sass版本为v7.0.1。
分析错误提示我们可以知道当前node-sass版本为v4.14.1。因此我得升级node-sass版本到7.0.1。
指令:npm install node-sass@7.0.1
升级好后,重新构建项目npm run build
,最后没有报错成功build。
注:这些指令本人均是在开发工具内置终端执行的。