Skip to content

Record a issue about node-sass

Published: at 03:03 PM

记录一次关于 node-sass 的坑点

问题解决

不支持 高版本 node 版本,会出现 ”gyp verb which failed Error: not found: python“ 系列问题,只需要 降低node 版本至 14.x 重新安装依赖即可解决

**原因:**因为项目依赖 sass-loader@7.1.0,而 sass-loader@7.1.0 依赖 node-sass 4.7.2,node-sass 4.7.2 需要 Node 14 支持

解决历程

最近频繁遇到好几次数据分析项目没办法跑起来的问题,针对于该问题做一次原因剖析

直接原因猜测:

  1. 依赖问题:可能是源不对或者包版本问题导致的依赖安装不正确
  2. 报错提示 python 未找到,本身这个问题出现的原因是 node-sass 导致,依赖了 python2,但是电脑安装了 python3,早起都能正常启动,有可能这不是问题。
  3. 安装依赖方式为 yarn

解决历程:

  1. 删除 package-lock.json \ yarn.lock \ node_modules \ next/node_modules 重新通过yarn安装依赖,安装好后运行 查看结果 结果不展示

    • 执行结果:gyp verb which failed Error: not found: python

      [2/4] 🚚  Fetching packages...
      [3/4] 🔗  Linking dependencies...
      warning " > tableexport@5.2.0" has unmet peer dependency "bootstrap@>= 3 < 4".
      warning " > babel-core@7.0.0-bridge.0" has unmet peer dependency "@babel/core@^7.0.0-0".
      [4/4] 🔨  Building fresh packages...
      [-/8] ⠄ waiting...
      [-/8] ⠄ waiting...
      [3/8] ⠄ node-sass
      [4/8] ⠄ fsevents
      **error /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-sass: Command failed.
      Exit code: 1**
      Command: node scripts/build.js
      Arguments:
      Directory: /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-sass
      Output:
      Building: /usr/local/bin/node /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/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 [
      gyp verb cli   '/usr/local/bin/node',
      gyp verb cli   '/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/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 verb cli ]
      gyp info using node-gyp@3.8.0
      gyp info using node@16.14.2 | darwin | 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 (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:13:12)
      gyp verb `which` failed     at F (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:68:19)
      gyp verb `which` failed     at E (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:80:29)
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:89:16
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/index.js:42:5
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/mode.js:8:5
      gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
      gyp verb `which` failed  python2 Error: not found: python2
      gyp verb `which` failed     at getNotFoundError (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:13:12)
      gyp verb `which` failed     at F (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:68:19)
      gyp verb `which` failed     at E (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:80:29)
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:89:16
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/index.js:42:5
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/mode.js:8:5
      gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
      gyp verb `which` failed   code: 'ENOENT'
      gyp verb `which` failed }
      **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 (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:13:12)
      gyp verb `which` failed     at F (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:68:19)
      gyp verb `which` failed     at E (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:80:29)
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:89:16
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/index.js:42:5
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/mode.js:8:5
      gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
      gyp verb `which` failed  python Error: not found: python
      gyp verb `which` failed     at getNotFoundError (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:13:12)
      gyp verb `which` failed     at F (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:68:19)
      gyp verb `which` failed     at E (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:80:29)
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:89:16
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/index.js:42:5
      gyp verb `which` failed     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/mode.js:8:5
      gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
      gyp verb `which` failed   code: 'ENOENT'
      gyp verb `which` failed }
      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 (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-gyp/lib/configure.js:484:19)
      gyp ERR! stack     at PythonFinder.<anonymous> (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-gyp/lib/configure.js:406:16)
      gyp ERR! stack     at F (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:68:16)
      gyp ERR! stack     at E (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:80:29)
      gyp ERR! stack     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:89:16
      gyp ERR! stack     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/index.js:42:5
      gyp ERR! stack     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/mode.js:8:5
      gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
      gyp ERR! System Darwin 21.5.0
      gyp ERR! command "/usr/local/bin/node" "/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
      gyp ERR! cwd /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-sass
      gyp ERR! node -v v16.14.2
      gyp ERR! node-gyp -v v3.8.0
      
  2. 直接通过 npm 安装依赖,安装好后运行 查看结果 结果不展示

  3. 删除 package-lock.json \ yarn.lock \ node_modules \ next/node_modules 重新通过 npm 安装依赖,安装好后运行 查看结果 结果不展示

    • 执行结果:npm ERR! gyp ERR! stack Error: Can’t find Python executable “python”, you can set the PYTHON env variable.

      $ npm i
      npm WARN deprecated @types/xlsx@0.0.36: This is a stub types definition for xlsx (<https://github.com/sheetjs/js-xlsx>). xlsx provides its own type definitions, so you don't need @types/xlsx installed!
      npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility>
      npm WARN deprecated source-map-url@0.4.1: See <https://github.com/lydell/source-map-url#deprecated>
      npm WARN deprecated 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).
      npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
      npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see <https://github.com/request/request/issues/3142>
      npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
      npm WARN deprecated urix@0.1.0: Please see <https://github.com/lydell/urix#deprecated>
      npm WARN deprecated har-validator@5.1.5: this library is no longer supported
      npm WARN deprecated eslint-loader@2.2.1: This loader has been deprecated. Please use eslint-webpack-plugin
      npm WARN deprecated resolve-url@0.2.1: <https://github.com/lydell/resolve-url#deprecated>
      npm WARN deprecated source-map-resolve@0.5.3: See <https://github.com/lydell/source-map-resolve#deprecated>
      npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
      npm WARN deprecated date-format@2.1.0: 2.x is no longer supported. Please upgrade to 4.x or higher.
      npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
      npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
      npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
      npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
      npm WARN deprecated sane@2.5.2: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
      npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
      npm WARN deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported
      npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
      npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
      npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See <https://v8.dev/blog/math-random> for details.
      npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See <https://v8.dev/blog/math-random> for details.
      npm WARN deprecated request@2.88.2: request has been deprecated, see <https://github.com/request/request/issues/3142>
      npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
      npm WARN deprecated axios@0.18.1: Critical security vulnerability fixed in v0.21.1. For more information, see <https://github.com/axios/axios/pull/3410>
      npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
      npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
      npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
      npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 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. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
      npm ERR! code 127
      npm ERR! path /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/fibers
      npm ERR! command failed
      npm ERR! command sh -c node build.js || nodejs build.js
      npm ERR! gyp info it worked if it ends with ok
      npm ERR! gyp info using node-gyp@3.8.0
      npm ERR! gyp info using node@16.14.2 | darwin | x64
      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.**
      npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-gyp/lib/configure.js:484:19)
      npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/node-gyp/lib/configure.js:406:16)
      npm ERR! gyp ERR! stack     at F (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:68:16)
      npm ERR! gyp ERR! stack     at E (/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:80:29)
      npm ERR! gyp ERR! stack     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/which/which.js:89:16
      npm ERR! gyp ERR! stack     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/index.js:42:5
      npm ERR! gyp ERR! stack     at /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/isexe/mode.js:8:5
      npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
      npm ERR! gyp ERR! System Darwin 21.5.0
      npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/.bin/node-gyp" "rebuild" "--release"
      npm ERR! gyp ERR! cwd /Users/wushuang/Documents/稿定/星图/代码仓库/user_profile_view/node_modules/fibers
      npm ERR! gyp ERR! node -v v16.14.2
      npm ERR! gyp ERR! node-gyp -v v3.8.0
      npm ERR! gyp ERR! not ok
      npm ERR! node-gyp exited with code: 1
      npm ERR! Please make sure you are using a supported platform and node version. If you
      npm ERR! would like to compile fibers on this machine please make sure you have setup your
      npm ERR! build environment--
      npm ERR! Windows + OS X instructions here: <https://github.com/nodejs/node-gyp>
      npm ERR! Ubuntu users please run: `sudo apt-get install g++ build-essential`
      npm ERR! RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`
      npm ERR! Alpine users please run: `sudo apk add python make g++`
      npm ERR! sh: nodejs: command not found
      
      npm ERR! A complete log of this run can be found in:
      npm ERR!     /Users/wushuang/.npm/_logs/2022-12-14T02_32_21_119Z-debug-0.log