项目里遇到css构建化工具,其中就有node-sass,但是安装过程中一直报错,怎么都安装不上,以下是解决思路与方法

  &npm install node-sass --save

这是大家常用的安装方法。由于nodesass安装过程中需要用到各种依赖,再加上国内网络环境……

使用cnpm便成了必要条件,切换命令为cnpm重试:

$npm set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
$npm install node-sass

接下来看报错,如果提示有python、gyp版本不对的,列了一大堆长长的提示的,是因为windows下缺乏Linux环境下的依赖,你可能需要把原来安装的node-sass删除重新安装,如果没有其他开发需求建议把python3或者原来的python2卸载后使用node重装。安装gyp可以使用下面的命令

$npm install -g node-gyp

安装期间会下载一个msi文件,如果电脑呆住,卡着不动了,人不要呆,去下载的文件夹下装一下那个文件,装完卡住了再执行下

至此安装应该能正常使用了。

 

思路延拓:

1yarn包管理工具,可以将网络下载的包缓存至本地,所以如果npm,cnpm都不好使,也可以换yarn进行安装

安装方法:

$yarn add node-sass

2如果安装node-sass时候安装在-g,也就是全局的时候,需要进node的全局依赖文件夹下将node-sass删除,并重新安装。建议不要全局安装。

3有时候安装失败了也会污染Windows下的环境变量,可以在失败时尝试

$npm rebuild node-sass

来重新构建一下,说不定有奇效~

4卸载在删除文件夹之后也要尝试下uninstall,这也是npm带的功能,可以在感觉没有删除干净的时候尝试一下

$npm uninstall node-sass

 

GitHub 加速计划 / no / node-sass
8.5 K
1.33 K
下载
:rainbow: Node.js bindings to libsass
最近提交(Master分支:23 天前 )
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> 7 个月前
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> 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐