记录在npm install node-sass 失败的问题

2020-04-08  本文已影响0人  jqboooo

先看报错问题

e_string.o.d.raw   -c -o Release/obj.target/binding/src/create_string.o ../src/create_string.cpp
../src/create_string.cpp:17:25: error: no matching constructor for initialization of 'v8::String::Utf8Value'
  v8::String::Utf8Value string(value);
                        ^      ~~~~~
/Users/bobo/.node-gyp/12.16.1/include/node/v8.h:3142:5: note: candidate constructor not viable: no known conversion from 'v8::Local<v8::Value>' to 'const v8::String::Utf8Value' for 1st argument
    Utf8Value(const Utf8Value&) = delete;
    ^
/Users/bobo/.node-gyp/12.16.1/include/node/v8.h:3135:5: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
    Utf8Value(Isolate* isolate, Local<v8::Value> obj);
    ^
1 error generated.
make: *** [Release/obj.target/binding/src/create_string.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/bobo/j2ee/gitcodes/renren-fast-vue/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.4.0
gyp ERR! command "/usr/local/bin/node" "/Users/bobo/j2ee/gitcodes/renren-fast-vue/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/bobo/j2ee/gitcodes/renren-fast-vue/node_modules/node-sass
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.9.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.9.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bobo/.npm/_logs/2020-04-02T05_47_33_104Z-debug.log

其实很简单,先定位错误的包:

gyp ERR! cwd /Users/bobo/j2ee/gitcodes/renren-fast-vue/node_modules/node-sass

然后再根据node和npm的版本指定要安装的node-sass版本

System Darwin 19.4.0
node -v v12.16.1
node-gyp -v v3.8.0
npm -v 6.14.4
Build failed with error code: 1

先通过指令安装,或是在package.json文件中的 dependencies 下配置:

...

"node-sass":"^4.13.0"

....

npm install node-sass@4.13.0

然后在重新执行下面操作:

// 1、清除npm缓存(由于是在Mac系统下,执行npm cache clean --force命令时前面需要加sudo获取权限)
sudo npm cache clean --force
// 2、删除node_modules文件(也可手动删除node_modules文件夹)
rm -rf node_modules
// 3、重新执行安装
npm install
上一篇下一篇

猜你喜欢

热点阅读