美文网首页
node-sass和dart-sass区别(以及解决M1芯片/a

node-sass和dart-sass区别(以及解决M1芯片/a

作者: Bhsun | 来源:发表于2021-09-23 18:04 被阅读0次

node-sass和dart-sass区别

我们先用vue-cli举例


vuecli创建项目
node-sass And dart-sass

在这时我们可以看到有两个sass解释器一个为node-sass,另一个为dart-sass。
这里建议选择大家使用dart-sass。而不要使用node-sass,下面我会解释一下为什么推荐大家使用dartsass。

单独安装和dart-sass或node-sass的命令先贴在下面

# 安装node-sass
npm install node-sass
# or
yarn add node-sass

# 安装dart-sass
npm install sass
# or
yarn add sass

我们选择dart-sass很重要的一点就是sass官方推荐使用dart-sass
往后的node-sass虽然会继续维护,但是不会再更新新功能。
不过就目前来说,node-sass在编译时依然比dart-sass拥有更好的性能(个人觉得编译时性能对开发不构成影响)。
国内网络对node-sass不太友好。

解决M1芯片无法使用node-sass

启动报错症状:

Error: Node Sass does not yet support your current environment: OS X Unsupported architecture (arm64) with Unsupported runtime (88) For more information on which environments are supported please see

安装报错症状:


安装报错症状
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:776:50: note: 'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
1 error generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/bari/Desktop/demovue/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 20.6.0
gyp ERR! command "/opt/homebrew/Cellar/node/16.9.1/bin/node" "/Users/bari/Desktop/demovue/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/bari/Desktop/demovue/node_modules/node-sass
gyp ERR! node -v v16.9.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

解决方案:
从package.json文件中找到node-sass删掉
然后使用命令安装dart-sass

# 安装dart-sass
npm install sass
# or
yarn add sass

问题原因:
这个问题的原因其实我们从node-sass的github上的版本中可以找到答案


node-sass6.0.1版本
node-sass5.0.0版本

可以看到都macOSX系统仅仅支持x64而M1芯片是arm64并不是x86。
也就是说如果我们的nodejs环境若为使用rosetta转译运行的x86 64位nodejs版本,那么就可以使用这个node-sass并且不会报错。
所以网上有些人说让回退nodejs版本,因为老版本nodejs不兼容arm64,那时候还没有M1芯片啊!QWQ。
老版本nodejs只能用resetta转译运行啊。

相关文章

网友评论

      本文标题:node-sass和dart-sass区别(以及解决M1芯片/a

      本文链接:https://www.haomeiwen.com/subject/chyogltx.html