项目依赖安装失败,node-sass 安装不上
-
cuibty 问:
问题描述
使用taro/cli创建项目成功 但是安装依赖报错
复现步骤
λ taro init Taro3 Taro v1.2.17 Taro即将创建一个新项目! Need help? Go and open issue: https://github.com/NervJS/taro/issues/new ? 请输入项目介绍! ? 是否需要使用 TypeScript ? Yes ? 请选择 CSS 预处理器(Sass/Less/Stylus) Sass ? 请选择模板 默认模板
报错信息
warning @tarojs/webpack-runner > webpack-format-messages > kleur@2.0.2: Please u pgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visi t <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s). warning eslint > file-entry-cache > flat-cache > circular-json@0.3.3: CircularJS ON is in maintenance only, flatted is its successor. warning eslint-plugin-typescript@0.12.0: Deprecated: Use @typescript-eslint/esli nt-plugin instead error C:\Users\IEUser\Desktop\Taro1\node_modules\node-sass: Command failed. Exit code: 1 Command: node scripts/build.js Arguments: Directory: C:\Users\IEUser\Desktop\Taro1\node_modules\node-sass Output: Building: C:\Program Files\nodejs\node.exe C:\Users\IEUser\Desktop\Taro1\node_mo dules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags = --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ 'C:\\Program Files\\nodejs\\node.exe', gyp verb cli 'C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\node-gyp\\bin\\ node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' ] gyp info using node-gyp@3.8.0 gyp info using node@10.15.3 | win32 | ia32 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "python2" in the PATH gyp verbwhichfailed Error: not found: python2 gyp verbwhichfailed at getNotFoundError (C:\Users\IEUser\Desktop\Taro1\n ode_modules\which\which.js:13:12) gyp verbwhichfailed at F (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:68:19) gyp verbwhichfailed at E (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:80:29) gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\which\ which.js:89:16 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ index.js:42:5 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ windows.js:36:5 gyp verbwhichfailed at FSReqWrap.oncomplete (fs.js:153:21) gyp verbwhichfailed python2 { Error: not found: python2 gyp verbwhichfailed at getNotFoundError (C:\Users\IEUser\Desktop\Taro1\n ode_modules\which\which.js:13:12) gyp verbwhichfailed at F (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:68:19) gyp verbwhichfailed at E (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:80:29) gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\which\ which.js:89:16 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ index.js:42:5 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ windows.js:36:5 gyp verbwhichfailed at FSReqWrap.oncomplete (fs.js:153:21) gyp verbwhichfailed stack: gyp verbwhichfailed 'Error: not found: python2\n at getNotFoundError ( C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:13:12)\n at F (C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:68:19)\n at E (C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:80:29)\n at C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:89:16\n at C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\isexe\\index.js:42:5\n at C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\isexe\\windows.js:36:5\n at FSReqWrap.oncomplete (fs.js:153:21)', gyp verbwhichfailed code: 'ENOENT' } gyp verb check python checking for Python executable "python" in the PATH gyp verbwhichfailed Error: not found: python gyp verbwhichfailed at getNotFoundError (C:\Users\IEUser\Desktop\Taro1\n ode_modules\which\which.js:13:12) gyp verbwhichfailed at F (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:68:19) gyp verbwhichfailed at E (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:80:29) gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\which\ which.js:89:16 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ index.js:42:5 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ windows.js:36:5 gyp verbwhichfailed at FSReqWrap.oncomplete (fs.js:153:21) gyp verbwhichfailed python { Error: not found: python gyp verbwhichfailed at getNotFoundError (C:\Users\IEUser\Desktop\Taro1\n ode_modules\which\which.js:13:12) gyp verbwhichfailed at F (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:68:19) gyp verbwhichfailed at E (C:\Users\IEUser\Desktop\Taro1\node_modules\whi ch\which.js:80:29) gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\which\ which.js:89:16 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ index.js:42:5 gyp verbwhichfailed at C:\Users\IEUser\Desktop\Taro1\node_modules\isexe\ windows.js:36:5 gyp verbwhichfailed at FSReqWrap.oncomplete (fs.js:153:21) gyp verbwhichfailed stack: gyp verbwhichfailed 'Error: not found: python\n at getNotFoundError (C :\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:13:12)\n at F (C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:68:19)\n a t E (C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:80:29)\n at C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\which\\which.js:89:16\n at C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\isexe\\index.js:42:5\n a t C:\\Users\\IEUser\\Desktop\\Taro1\\node_modules\\isexe\\windows.js:36:5\n a t FSReqWrap.oncomplete (fs.js:153:21)', gyp verbwhichfailed code: 'ENOENT' } gyp verb could not find "python". checking python launcher gyp verb could not find "python". guessing location gyp verb ensuring that file exists: C:\Python27\python.exe gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT HON env variable. gyp ERR! stack at PythonFinder.failNoPython (C:\Users\IEUser\Desktop\Taro1\n ode_modules\node-gyp\lib\configure.js:484:19) gyp ERR! stack at PythonFinder.<anonymous> (C:\Users\IEUser\Desktop\Taro1\no de_modules\node-gyp\lib\configure.js:509:16) gyp ERR! stack at C:\Users\IEUser\Desktop\Taro1\node_modules\graceful-fs\pol yfills.js:282:31 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:153:21) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\IEUser\\Deskt op\\Taro1\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--li bsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd C:\Users\IEUser\Desktop\Taro1\node_modules\node-sass gyp ERR! node -v v10.15.3 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok Build failed with error code: 1 yarn install v1.13.0 info No lockfile found. [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.7: The platform "win32" is incompatible with this module. info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
系统信息
Taro CLI 1.2.17 environment info: System: OS: Windows 7 Binaries: Node: 10.15.3 - C:\Program Files\nodejs\node.EXE Yarn: 1.13.0 - C:\Program Files\Yarn\bin\yarn.CMD npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
回复一:
你的错误日志格式太乱,可以的话希望修改一下方便确认问题所在,从以下两段日志看,是 node-sass 这个依赖安装失败了
C:\Users\IEUser\Desktop\Taro1\node_modules\node-sass: Command failed. Exit code: 1 check python checking for Python executable "python2" in the PATH gyp verbwhichfailed Error: not found: python2 gyp verbwhichfailed at getNotFoundError
你可以根据以下提供的链接获取一些有用信息
cuibty 回复,问题依旧存在:
全新安装完系统 win 10 pro 1809 (MSDN)问题依旧。 安装完系统后就安装了个nodejs v10.15.3 和 yarn v1.13.0。 λ taro init Taro2 � Taro v1.2.17 Taro即将创建一个新项目! Need help? Go and open issue: https://github.com/NervJS/taro/issues/new ? 请输入项目介绍! ? 是否需要使用 TypeScript ? Yes ? 请选择 CSS 预处理器(Sass/Less/Stylus) Sass ? 请选择模板 默认模板 ✔ 创建项目: Taro2 ✔ 创建配置目录: Taro2/config ✔ 创建源码目录: Taro2/src ✔ 创建页面目录: Taro2/src/pages ✔ 创建页面 JS 文件: Taro2/src/pages/index/index.tsx ✔ 创建页面 SCSS 文件: Taro2/src/pages/index/index.scss ✔ 创建文件: Taro2/src/app.tsx ✔ 创建文件: Taro2/src/app.scss ✔ 创建文件: Taro2/src/index.html ✔ 创建文件: Taro2/config/index.js ✔ 创建文件: Taro2/config/dev.js ✔ 创建文件: Taro2/config/prod.js ✔ 创建文件: Taro2/.editorconfig ✔ 创建文件: Taro2/.gitignore ✔ 创建文件: Taro2/package.json ✔ 创建文件: Taro2/.eslintrc ✔ 创建文件: Taro2/project.config.json √ Initialized empty Git repository in C:/Users/cuibty/Desktop/Taro2/.git/ × 安装项目依赖失败,请自行重新安装! warning @tarojs/webpack-runner > webpack-format-messages > kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit https://github.com/lukeed/kleur/releases/tag/v3.0.0\ for migration path(s). warning eslint > file-entry-cache > flat-cache > circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor. warning eslint-plugin-typescript@0.12.0: Deprecated: Use @typescript-eslint/eslint-plugin instead error C:\Users\cuibty\Desktop\Taro2\node_modules\node-sass: Command failed. Exit code: 1 Command: node scripts/build.js Arguments: Directory: C:\Users\cuibty\Desktop\Taro2\node_modules\node-sass Output: Building: D:\Program Files\nodejs\node.exe C:\Users\cuibty\Desktop\Taro2\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ 'D:\Program Files\nodejs\node.exe', gyp verb cli 'C:\Users\cuibty\Desktop\Taro2\node_modules\node-gyp\bin\node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' ] gyp info using node-gyp@3.8.0 gyp info using node@10.15.3 | win32 | x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "python2" in the PATH gyp verb which failed Error: not found: python2 gyp verb which failed at getNotFoundError (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:13:12) gyp verb which failed at F (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:68:19) gyp verb which failed at E (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:80:29) gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:89:16 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\index.js:42:5 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\windows.js:36:5 gyp verb which failed at FSReqWrap.oncomplete (fs.js:153:21) gyp verb which failed python2 { Error: not found: python2 gyp verb which failed at getNotFoundError (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:13:12) gyp verb which failed at F (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:68:19) gyp verb which failed at E (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:80:29) gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:89:16 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\index.js:42:5 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\windows.js:36:5 gyp verb which failed at FSReqWrap.oncomplete (fs.js:153:21) gyp verb which failed stack: gyp verb which failed 'Error: not found: python2\n at getNotFoundError (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:13:12)\n at F (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:68:19)\n at E (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:80:29)\n at C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:89:16\n at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\index.js:42:5\n at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\windows.js:36:5\n at FSReqWrap.oncomplete (fs.js:153:21)',gyp verb which failed code: 'ENOENT' } gyp verb check python checking for Python executable "python" in the PATH gyp verb which failed Error: not found: python gyp verb which failed at getNotFoundError (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:13:12) gyp verb which failed at F (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:68:19) gyp verb which failed at E (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:80:29) gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:89:16 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\index.js:42:5 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\windows.js:36:5 gyp verb which failed at FSReqWrap.oncomplete (fs.js:153:21) gyp verb which failed python { Error: not found: python gyp verb which failed at getNotFoundError (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:13:12) gyp verb which failed at F (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:68:19) gyp verb which failed at E (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:80:29) gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:89:16 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\index.js:42:5 gyp verb which failed at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\windows.js:36:5 gyp verb which failed at FSReqWrap.oncomplete (fs.js:153:21) gyp verb which failed stack: gyp verb which failed 'Error: not found: python\n at getNotFoundError (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:13:12)\n at F (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:68:19)\n at E (C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:80:29)\n at C:\Users\cuibty\Desktop\Taro2\node_modules\which\which.js:89:16\n at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\index.js:42:5\n at C:\Users\cuibty\Desktop\Taro2\node_modules\isexe\windows.js:36:5\n at FSReqWrap.oncomplete (fs.js:153:21)', gyp verb which failed code: 'ENOENT' } gyp verb could not find "python". checking python launcher gyp verb could not find "python". guessing location gyp verb ensuring that file exists: C:\Python27\python.exe gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. gyp ERR! stack at PythonFinder.failNoPython (C:\Users\cuibty\Desktop\Taro2\node_modules\node-gyp\lib\configure.js:484:19) gyp ERR! stack at PythonFinder. (C:\Users\cuibty\Desktop\Taro2\node_modules\node-gyp\lib\configure.js:509:16) gyp ERR! stack at C:\Users\cuibty\Desktop\Taro2\node_modules\graceful-fs\polyfills.js:282:31 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:153:21) gyp ERR! System Windows_NT 10.0.17763 gyp ERR! command "D:\Program Files\nodejs\node.exe" "C:\Users\cuibty\Desktop\Taro2\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd C:\Users\cuibty\Desktop\Taro2\node_modules\node-sass gyp ERR! node -v v10.15.3 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok Build failed with error code: 1 yarn install v1.13.0 info No lockfile found. [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.7: The platform "win32" is incompatible with this module. info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. 创建项目 Taro2 成功! 请进入项目目录 Taro2 开始工作吧!�
回复二:
Taro 使用了 node-sass 4.11.0,查了一下 node-sass 的 Release ,Windows 上 Node.js 10+ 确实是支持的版本。
https://github.com/sass/node-sass/releases/tag/v4.11.0https://github.com/NervJS/taro/blob/v1.2.17/packages/taro-webpack-runner/package.json#L48
https://github.com/NervJS/taro/blob/v1.2.17/packages/taro-plugin-sass/package.json#L19Taro 文档中,Debug 指南部分有提到 node-sass 安装不上的问题,你可以尝试一下里面的方案
另外由于 node-sass 本身的特殊性,可能需要从源代码进行编译,使用的编译工具是 node-gyp。node-gyp 在 Windows 上需要两个重要组件,Visual Studio Build Tools 和 Python 2.7 ,在上文中你指出你的 Windows 10 是全新安装的,可能因为该问题导致 node-gyp 编译 node-sass 失败,如果你认为你的问题与该原因有关,可以参考以下链接获取更多信息
https://github.com/nodejs/node-gyp#on-windows
https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modulescuibty 回复:
yarn config set registry http://registry.npm.taobao.org yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass
或者
npm set registry https://registry.npm.taobao.org npm set sass_binary_site https://npm.taobao.org/mirrors/node-sass
安装依赖成功!
总结:
这不是Taro的问题。node-sass 安装过程中,需要从一个海外的地址下载二进制内容。
如果安装环境与这个海外地址无法建立有效的链接,就会导致项目依赖安装失败。可以安装 mirror-config-china,将下载地址更换为国内的镜像。