在我的服务器(Ubuntu 16.04)上安装node-sass
时遇到问题。在我的本地服务器上,我没有这些错误...
NodeJS版本:v10.2.1
Npm版本:5.6.0
节点sass版本:^ 4.9.0
错误讯息:
****@web-test:/var/www/****$ sudo npm i node-sass
> node-sass@4.9.0 install /var/www/****/node_modules/node-sass
> node scripts/install.js
Unable to save binary /var/www/****/node_modules/node-sass/vendor/linux-x64-64 : { Error: EACCES: permission denied, mkdir '/var/www/****/node_modules/node-sass/vendor'
at Object.fs.mkdirSync (fs.js:872:3)
at sync (/var/www/****/node_modules/mkdirp/index.js:71:13)
at Function.sync (/var/www/****/node_modules/mkdirp/index.js:77:24)
at checkAndDownloadBinary (/var/www/****/node_modules/node-sass/scripts/install.js:114:11)
at Object.<anonymous> (/var/www/****/node_modules/node-sass/scripts/install.js:157:1)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
errno: -13,
syscall: 'mkdir',
code: 'EACCES',
path: '/var/www/****/node_modules/node-sass/vendor' }
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/****/node_modules/node-sass/build'
gyp ERR! System Linux 4.4.0-116-generic
gyp ERR! command "/usr/local/bin/node" "/var/www/****/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/****/node_modules/node-sass
gyp ERR! node -v v10.2.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed with error code: 1
npm WARN ****@1.0.0 No repository field.
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! /home/****/.npm/_logs/2018-06-04T14_54_18_635Z-debug.log
该文件夹的权限: drwxr-xr-x 11 root root 4096 june 4 17:25 ****
错误:
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stackbcrypt_lib.target.mk:97: recipe for target 'Release/obj.target/bcrypt_lib/src/bcrypt_node.o' failed
make: *** [Release/obj.target/bcrypt_lib/src/bcrypt_node.o] Error 1
make: Leaving directory '/var/www/****/node_modules/bcrypt/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Linux 4.4.0-116-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/var/www/****/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/var/www/****/node_modules/bcrypt/lib/binding"
gyp ERR! cwd /var/www/****/node_modules/bcrypt
gyp ERR! node -v v10.2.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Linux 4.4.0-116-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/var/www/****/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/var/www/****/node_modules/bcrypt/lib/binding"
gyp ERR! cwd /var/www/****/node_modules/bcrypt
gyp ERR! node -v v10.2.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/var/www/****/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/var/www/****/node_modules/bcrypt/lib/binding' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/var/www/****/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:961:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
node-pre-gyp ERR! System Linux 4.4.0-116-generic
node-pre-gyp ERR! command "/usr/local/bin/node" "/var/www/****/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd /var/www/****/node_modules/bcrypt
node-pre-gyp ERR! node -v v10.2.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.36
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/var/www/****/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/var/www/****/node_modules/bcrypt/lib/binding' (1)
npm WARN ****@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@1.0.3 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@1.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
正确的解决方案(经过多次搜索):
sudo rm -rf ~/.node-gyp
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm i --unsafe-perm
答案 0 :(得分:0)
似乎root
用户是唯一有权访问/www/var
文件夹的用户。为此创建一个专用用户会更好。
首先,使用以下命令检查您当前登录的用户:
$ whoami
并更新该用户的目标文件夹的权限:
sudo chown -R $USER /var/www/[YOUR FOLDER]
最后再次运行npm install
。