nodejs12版本安装node-sass失败各类解决方案(全)

今天把node 版本升级到12.10,想体验下新特性,可是没想到 在安装node-sass时出现了意外,

就我的经验来讲,本人启动的 npm i 命令次数也很多了,node-sass安装失败的缘由,总结下来也就几种
最多见的报错
1.没有权限: 解决方法
    第一种: npm install --unsafe-perm node-sass 
            --unsafe-perm: 在root下默认值为false,其余的默认值为true
            设置为true,在run package script时会切换UID/GID 明确设置为false,在非root用户下安装会失败
    第二种  npm install --user=root node-sass 
            --user=root:指定了在执行脚本时使用的帐号(UID),默认是nobody
            应该还有其余解决方案,可是通常这两种基本能解决问题

2.网络缘由, 安装 node-sass 时在 node scripts/install 阶段会从 github.com 上下载一个 .node文件,
            大部分安装不成功的缘由都源自这里,
            由于 GitHub Releases 里的文件都托管在 s3.amazonaws.com 
            上面,而这个网址在国内老是网络不稳定,
            因此咱们须要经过第三方服务器下载这个文件。:
    解决方法:
    
    第一种  设置淘宝源 npm config set registry https://registry.npm.taobao.org;
    第二种  用cnpm 
            先全局安装 cnpm  npm i cnpm -g
            cnpm i node-sass -D
    第三种 在项目中添加 .npmrc文件
            sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
            registry=https://registry.npm.taobao.org
            而后直接 npm install便可 注意安装 node-sass就会自动从淘宝源上下载
复制代码

可是今天拉项目的时候又发现了一种:node版本与fsevents版本不兼容。问题复现

node版本12.10.1 fsevents版本1.2.1,若是node版本在12如下的应该没有影响,可是,若是node版本是12的话 运行npm i 运行日志会报错:
../../../../nan/nan_converters_43_inl.h:22:1: warning: 'ToBoolean' is deprecated: ToBoolean can never throw. Use Local version. [-Wdeprecated-declarations]
X(Boolean)
^
../../../../nan/nan_converters_43_inl.h:18:12: note: expanded from macro 'X'
      val->To ## TYPE(isolate->GetCurrentContext()) \\\n ^
<scratch space>:201:1: note: expanded from here
ToBoolean
^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:2523:3: note: 'ToBoolean' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON(\"ToBoolean can never throw. Use Local version.\", ^ /Users/rene/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON' declarator __attribute__((deprecated(message))) ^ In file included from ../fsevents.cc:6: In file included from ../../../../nan/nan.h:221: In file included from ../../../../nan/nan_converters.h:67: ../../../../nan/nan_converters_43_inl.h:40:1: warning: 'BooleanValue' is deprecated: BooleanValue can never throw. Use Isolate version. [-Wdeprecated-declarations] X(bool, Boolean) ^ ../../../../nan/nan_converters_43_inl.h:37:15: note: expanded from macro 'X' return val->NAME ## Value(isolate->GetCurrentContext()); \\\n ^ <scratch space>:208:1: note: expanded from here BooleanValue ^ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:2561:3: note: 'BooleanValue' has been explicitly marked deprecated here V8_DEPRECATED(\"BooleanValue can never throw. Use Isolate version.\", ^ /Users/rene/.node-gyp/12.1.0/include/node/v8config.h:307:29: note: expanded from macro 'V8_DEPRECATED' declarator __attribute__((deprecated(message))) ^ In file included from ../fsevents.cc:6: In file included from ../../../../nan/nan.h:222: In file included from ../../../../nan/nan_new.h:189: ../../../../nan/nan_implementation_12_inl.h:103:42: error: no viable conversion from 'v8::Isolate *' to 'Local<v8::Context>' return scope.Escape(v8::Function::New( isolate ^~~~~~~ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:183:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'v8::Isolate *' to 'const v8::Local<v8::Context> &' for 1st argument class Local { ^ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:183:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'v8::Isolate *' to 'v8::Local<v8::Context> &&' for 1st argument /Users/rene/.node-gyp/12.1.0/include/node/v8.h:187:13: note: candidate template ignored: could not match 'Local<type-parameter-0-0>' against 'v8::Isolate *' V8_INLINE Local(Local<S> that) ^ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:4126:22: note: passing argument to parameter 'context' here Local<Context> context, FunctionCallback callback, ^ In file included from ../fsevents.cc:6: In file included from ../../../../nan/nan.h:222: In file included from ../../../../nan/nan_new.h:189: ../../../../nan/nan_implementation_12_inl.h:337:37: error: too few arguments to function call, expected 2, have 1 return v8::StringObject::New(value).As<v8::StringObject>(); ~~~~~~~~~~~~~~~~~~~~~ ^ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:5380:3: note: 'New' declared here static Local<Value> New(Isolate* isolate, Local<String> value); ^ In file included from ../fsevents.cc:6: In file included from ../../../../nan/nan.h:222: In file included from ../../../../nan/nan_new.h:189: ../../../../nan/nan_implementation_12_inl.h:337:58: error: expected '(' for function-style cast or type construction return v8::StringObject::New(value).As<v8::StringObject>(); ~~~~~~~~~~~~~~~~^ ../../../../nan/nan_implementation_12_inl.h:337:60: error: expected expression return v8::StringObject::New(value).As<v8::StringObject>(); ^ In file included from ../fsevents.cc:6: ../../../../nan/nan.h:1063:44: error: no matching member function for call to 'ToString' v8::Local<v8::String> string = from->ToString(); ~~~~~~^~~~~~~~ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:2528:44: note: candidate function not viable: requires single argument 'context', but no arguments were provided V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString( ^ /Users/rene/.node-gyp/12.1.0/include/node/v8.h:2544:35: note: candidate function not viable: requires single argument 'isolate', but no arguments were provided Local<String> ToString(Isolate* isolate) const); ^ In file included from ../fsevents.cc:6: ... 复制代码
这是由于 项目中的 fsevents版本比较低,只有1.2.9以上的才支持node12版本,因此致使编译不经过.
解决方法以下:
删除node_moules文件夹
删除package-lock.json文件
安装最新版本的 fsevents:  npm i fsevents -D
而后从新安装依赖 npm i
解决
复制代码
这种状况通常出如今 本地node版本较高,可是项目中的fsevents版本比较低的时候

注意!

如今能够用 dart-sass 无缝替换 node-sass 了!dart-sass 兼容 node-sass 的 API,并且安装过程无需下载二进制文件,这样你们就不须要用本篇文章的方式安装 node-sass 了。

相关文章
相关标签/搜索