node-sass这个包不同于普通的npm包,他的源码是C++实现的,因为编译Sass需要使用LibSass,后者是C语言实现的。node-sass实际是调用LibSass进而实现编译sass文件的。

node-sass代码主要是通过C++实现的

固Node-sass 是需要编译的。

考虑到平台兼容问题,node-sass可能需要到你的电脑上进行现场编译(区别于直接下载预编译好的文件)。这时候就需要跨平台编译工具的node-gyp的支持,而node-gyp在windows下是依赖于python的。

// 固有此错误
gyp ERR! find Python : gyp错误,找不到python



了解了这个原理,解决方式就有两种

node-sass直接从指定站点下载预编译好的文件
安装node-gyp编译所需要的的依赖,(不仅仅是python)
对于第一种方式

# windows powershell 命令行中定义变量(若系统不同,请自行修改)。
$env:SASS_BINARY_SITE="http://npm.taobao.org/mirrors/node-sass"

# 顺带说一句cypress也可以同样设置
$env:CYPRESS_INSTALL_BINARY="https://npm.taobao.org/mirrors/cypress/7.5.0/win32-x64/cypress.zip"

对于第二种方式

# 安装windows平台构建工具,此过程会安装python.
npm install --global windows-build-tools

之后可以尝试再次安装

GitHub 加速计划 / no / node-sass
10
0
下载
:rainbow: Node.js bindings to libsass
最近提交(Master分支:1 个月前 )
6081731a Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 1 年前
62c0f46c Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 1 年前
Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐