记录一个在 laradock 中运行 NPM install 或 yarn install 遇到的坑

将线上的项目 git clone 重新部署到本地的时候(第一次部署到本地OK的,第二次部署到本地另一个位置出问题了),在 laradock 环境中 composer install 安装OK,然后 安装vue 环境,执行 npm install 或者 yarn install 的时候,出错:

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 (/var/www/send/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/var/www/send/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/var/www/send/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /var/www/send/node_modules/which/which.js:89:16
gyp verb `which` failed     at /var/www/send/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /var/www/send/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/var/www/send/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/var/www/send/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/var/www/send/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /var/www/send/node_modules/which/which.js:89:16
gyp verb `which` failed     at /var/www/send/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /var/www/send/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python2\n    at getNotFoundError (/var/www/send/node_modules/which/which.js:13:12)\n    at F (/var/www/send/node_modules/which/which.js:68:19)\n    at E (/var/www/send/node_modules/which/which.js:80:29)\n    at /var/www/send/node_modules/which/which.js:89:16\n    at /var/www/send/node_modules/isexe/index.js:42:5\n    at /var/www/send/node_modules/isexe/mode.js:8:5\n    at FSReqWrap.oncomplete (fs.js:154: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 (/var/www/send/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/var/www/send/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/var/www/send/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /var/www/send/node_modules/which/which.js:89:16
gyp verb `which` failed     at /var/www/send/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /var/www/send/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed  python { Error: not found: python
gyp verb `which` failed     at getNotFoundError (/var/www/send/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/var/www/send/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/var/www/send/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /var/www/send/node_modules/which/which.js:89:16
gyp verb `which` failed     at /var/www/send/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /var/www/send/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python\n    at getNotFoundError (/var/www/send/node_modules/which/which.js:13:12)\n    at F (/var/www/send/node_modules/which/which.js:68:19)\n    at E (/var/www/send/node_modules/which/which.js:80:29)\n    at /var/www/send/node_modules/which/which.js:89:16\n    at /var/www/send/node_modules/isexe/index.js:42:5\n
    at /var/www/send/node_modules/isexe/mode.js:8:5\n    at FSReqWrap.oncomplete (fs.js:154:21)',
gyp verb `which` failed   code: 'ENOENT' }

出现了很多 python , python2 什么的。。。
或者在上面出错的情况下,编译本地文件执行 npm run watch-poll (或 npm run dev) 的时候,出现另一种错误:

ERROR in ./node_modules/css-loader??ref--5-2!./node_modules/postcss-loader/lib??postcss!./node_modules/resolve-url-loader??ref--5-4!./node_modules/sass-loader/lib/loader.js??ref--5-5!./resources/assets/frontend/sass/app.scss
Module build failed: Error: Missing binding /var/www/send/node_modules/node-sass/vendor/linux-x64-64/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 10.x

Found bindings for the following environments:
  - Linux 64-bit with Node.js 10.x

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
    at module.exports (/var/www/send/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/var/www/send/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.sassLoader (/var/www/send/node_modules/sass-loader/lib/loader.js:46:72)
 @ ./resources/assets/frontend/sass/app.scss 4:14-278
 @ multi ./resources/assets/frontend/js/app.js ./resources/assets/frontend/sass/app.scss

ERROR in ./resources/assets/frontend/sass/app.scss
Module build failed: ModuleBuildError: Module build failed: Error: Missing binding /var/www/send/node_modules/node-sass/vendor/linux-x64-64/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 10.x

Found bindings for the following environments:
  - Linux 64-bit with Node.js 10.x

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
    at module.exports (/var/www/send/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/var/www/send/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.sassLoader (/var/www/send/node_modules/sass-loader/lib/loader.js:46:72)
    at runLoaders (/var/www/send/node_modules/webpack/lib/NormalModule.js:195:19)
    at /var/www/send/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /var/www/send/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at runSyncOrAsync (/var/www/send/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/var/www/send/node_modules/loader-runner/lib/LoaderRunner.js:229:2)
    at /var/www/send/node_modules/loader-runner/lib/LoaderRunner.js:202:4
    at /var/www/send/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:70:14
    at process._tickCallback (internal/process/next_tick.js:61:11)
 @ ./resources/assets/frontend/sass/app.scss
 @ multi ./resources/assets/frontend/js/app.js ./resources/assets/frontend/sass/app.scss

根据提示 npm install node-sass 或 yarn add node-sass 无效。。。

解决办法:
更换 npm 镜像为阿里镜像:
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install node-sass

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 1

谢谢老哥,能讲一下具体的原理么,为啥必须要通过cnpm install node-sass命令更新SASS_BINARY_SITE=npm.taobao.org/mirrors/node-sass yarn官方这个命令和你的有啥区别么,我yarn也换了淘宝源

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!