首先声明,如果安装 node-sass 或者 npm install 报错,大概率是因为 node 版本和 node-sass 版本不兼容导致的问题,所以请先确认两者版本不冲突。

如下是 node 和 node-sass 版本依赖关系表:

如果你的 node 版本和 node-sass 版本没有问题,请继续往下看。 

node sass 是什么?

Node-sass 是一个库,它将Node.js绑定到LibSass(流行样式表预处理器Sass的C版本)。它允许用户以令人难以置信的速度将.scss文件本地编译为css,并通过连接中间件自动编译。

Sass是什么?

sass是一种预处理器脚本语言,可以解释或编译成层叠样式表(CSS)。

vue项目中安装使用scss时,需要安装node-sass  及  sass-loader

第一步,安装淘宝镜像

npm install -g cnpm --registry=https://registry.npm.taobao.org

第二部,安装node-sass

cnpm install --save-dev node-sass

安装node-sass时可能会出现如下错误:

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\Administrator\Desktop\vueVant\vuevant\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\Administrator\Desktop\vueVant\vuevant\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at callback (C:\Users\Administrator\Desktop\vueVant\vuevant\node_modules\graceful-fs\polyfills.js:295:20)
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:166:21)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "E:\\nodejs-12.16\\node.exe" "C:\\Users\\Administrator\\Desktop\\vueVant\\vuevant\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\Administrator\Desktop\vueVant\vuevant\node_modules\node-sass
gyp ERR! node -v v12.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

报错如上述问题,安装不成功可能是由于网速或者版本的问题,那么首先你应该卸载之前安装的东西:

npm uninstall node-sass

然后重装,或者转而使用淘宝镜像安装。重复以上步骤即可。

或者也可能报如下错误:

Module build failed: Error: ENOENT: no such file or directory, scandir 
'F:\WEB\project\ZhongJun\sgb-management-client\node_modules\_node-sass@4.14.1@node-sass\vendor'

这时需要使用 npm命令重新编译node-sass,如下:

npm rebuild node-sass

第三部,安装sass-loader:

npm install sass-loader --save-dev

同样可以选择淘宝镜像安装。

:当你在多个node版本之间切换,或者频繁 npm install 时,你应该及时清除 npm 缓存

npm cache clean --force

参考:npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.14.1 postinstall: `node scripts/build_lilyheart1的博客-CSDN博客




 

报错 npm ERR! Invalid dependency type requested: alias

如上报错是因为npm 版本过低,无法编译 alias 语法

解决方案是需要提升本地安装 npm 的版本,但是由于本地有 alias 语法存在,所以执行 npm install -g npm 会报错,陷入死循环。。。

本人遇到这个问题的具体环境:

node版本 10.15.3

npm版本  6.4.1

解决方案:手动替换 当前node环境的npm 版本为6.9以上版本。

手动替换 c盘 paogram Files 文件夹下 nodejs 文件夹中 npm、npm.cmd、npx、npx.cmd为6.9以上版本,nodejs文件夹node_modules 文件中 npm 依赖文件为 6.9以上版本。

同时手动替换 nvm 安装目录下node版本对应的文件夹中的 npm 为 6.9以上版本,操作同上。

我本地 nvm 安装目录:C:\Users\liuweixiang\AppData\Roaming\nvm

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

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

更多推荐