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 了。

相關文章
相關標籤/搜索