node-sass 常出现的两个问题


一、node-sass 不支持 Mac M1

运行安装 node-sass 的项目报错如下

Syntax Error: Error: Node Sass does not yet support your current environment: OS X Unsupported architecture (arm64) with Node.js 14.x
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.0

不支持 Mac M1 的 Arm 架构

解决方式

// 1.删除项目依赖包 
rm -rf node_modules 
// 2.重新安装依赖 最好使用最新的淘宝源 registry=https://registry.npmmirror.com
npm install
// 3.安装 sass
npm install sass
// 重新运行项目即可正常运行

二、node-sass 不支持当前 node 版本

node-sass 对 node 版本的支持比较慢,通常会落下多个正式的 node 版本,一般来说安装当前版本的前两到三个正式版本即可

解决方式

以 Mac M1 的 brew 安装器的操作为例

# 1.取消当前node版本的链接
$ brew unlink node

# 2.查询当前有哪些可用node版本
$ brew search node
==> Formulae
libbitcoin-node     node-build          node@14 ✔           nodeenv
linode-cli          node-sass           node@16             nodenv
llnode              node@10             node_exporter       ode
node ✔              node@12             nodebrew

# 3.这里选择安装 node@14
$ brew install node@14

# 4.安装成功后链接到 node@14 版本 会出现如下提示,安照提示删除提示的文件即可
$ brew link node@14
Linking /opt/homebrew/Cellar/node@14/14.19.3...
Error: Could not symlink bin/npm
Target /opt/homebrew/bin/npm
already exists. You may want to remove it:
  rm '/opt/homebrew/bin/npm'

To force the link and overwrite all conflicting files:
  brew link --overwrite node@14

To list all files that would be deleted:
  brew link --overwrite --dry-run node@14
  
# 5.因为新的node版本会携带相关的包,和前一个node版本的起冲突,删除一个然后提示下一个,
#   具体路径按照自己终端的提示删除(删除需谨慎)
$ rm /opt/homebrew/bin/npm

# 6.删除后重新 link 出现如下提示则为切换 node 版本成功
$ brew link node@14
Linking /opt/homebrew/Cellar/node@14/14.19.3... 3900 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/node@14/bin:$PATH"' >> ~/.zshrc
  
# 7.查看node版本,确认是否替换成功
$ node -v
v14.19.3
$ npm -v
6.14.17
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐