VUE-015-解决 vue install 引发的 failed Error: not found: python2 问题

好久没写 vue 相关的文章内容,此次文章标题问题起因是使用 npm 时,提示版本较低,建议升级,就盲从了一把,后面就是泪了,此处略过,不再细表,回归正题。

 

发生 install 异常时,提示信息如下所示:

npm ERR! code 1
npm ERR! path U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\node-sass
npm ERR! command failed
npm ERR! command U:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: D:\EnvTool\nodejs\node.exe U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_c
flags= --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   'U:\\EnvTool\\nodejs\\node.exe',
npm ERR! gyp verb cli   'G:\\cnblogs\\fanfengping-dtops\\fanfengping-dtops-front\\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@12.22.12 | 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 getNotFoundError (U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:168:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:168: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` succeeded python U:\Python37\python.EXE
npm ERR! gyp ERR! configure error

从错误信息里看是 python 环境有问题,网上百度了一下都是重新安装配置 python2的环境或更换npm源,实际环境未进行变更,因而可以排除环境问题。

后来搜索到 node-sass 安装后,会自动执行 node-sass/scripts 下的 build.js,导致运行错误。

 

解决方法:

1、不重新安装配置 python 2

2、不更新 npm 安装源

3、进行 install 时不执行忽略构建脚本

npm install node-sass --ignore-scripts
npm install --ignore-scripts
npm install

4、若在 run dev 的时候,出现如下所示的错误

 error  in ./src/components/Breadcrumb/index.vue?vue&type=style&index=0&id=b50ef614&rel=stylesheet%2Fscss&lang=scss&scoped=true&

Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: ENOENT: no such file or directory, scandir 'U:\cnblogs\fanfengping-dtops\fanfengping-dtops-front\node_modules\node-sass\vendor'
    at Object.readdirSync (fs.js:955:3)

执行如下命令,重新编译构建一下 node-sass 即可。

npm rebuild node-sass

 

posted @ 2022-04-24 16:16  范丰平  Views(3354)  Comments(0Edit  收藏  举报