求助,使用vue时安装node-sass报错

beimyy 2018-06-28 12:42:05
使用vue时安装node-sass报错

在服务器上部署vue项目时,node-sass安装不了,导致项目不能build,特来此求助.

操作系统是centos7
```shell
[root@vm172-31-48-7 apps]# uname -sr
Linux 3.10.0-693.21.1.el7.x86_64
```

node版本
```shell
[root@vm172-31-48-7 vuetest]# node -v
v8.11.3
[root@vm172-31-48-7 vuetest]# npm -v
6.1.0

```
通过vue-cli搭建了项目
```shell
vue init webpack vuetest
cd vuetest
npm install
```
到这里一切正常.
安装sass-loader
```shell
[root@vm172-31-48-7 vuetest]# npm install sass-loader --save-dev --registry=https://registry.npm.taobao.org
```
安装成功,然后安装node-sass失败
```shell
[root@vm172-31-48-7 vuetest]# npm install node-sass --save-dev --registry=https://registry.npm.taobao.org

> node-sass@4.9.0 install /apps/vuetest/node_modules/node-sass
> node scripts/install.js

Unable to save binary /apps/vuetest/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/apps/vuetest/node_modules/node-sass/vendor'
at Object.fs.mkdirSync (fs.js:885:18)
at sync (/apps/vuetest/node_modules/mkdirp/index.js:71:13)
at Function.sync (/apps/vuetest/node_modules/mkdirp/index.js:77:24)
at checkAndDownloadBinary (/apps/vuetest/node_modules/node-sass/scripts/install.js:114:11)
at Object.<anonymous> (/apps/vuetest/node_modules/node-sass/scripts/install.js:157:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/apps/vuetest/node_modules/node-sass/vendor' }

> node-sass@4.9.0 postinstall /apps/vuetest/node_modules/node-sass
> node scripts/build.js

Building: /usr/local/node/bin/node /apps/vuetest/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/local/node/bin/node',
gyp verb cli '/apps/vuetest/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library=' ]
gyp info using node-gyp@3.7.0
gyp info using node@8.11.3 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import platform; print(platform.python_version());"` returned: "2.7.5\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.11.3
gyp verb command install [ '8.11.3' ]
gyp verb install input version string "8.11.3"
gyp verb install installing version: 8.11.3
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 8.11.3
gyp verb build dir attempting to create "build" dir: /apps/vuetest/node_modules/node-sass/build
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/apps/vuetest/node_modules/node-sass/build'
gyp ERR! System Linux 3.10.0-693.21.1.el7.x86_64
gyp ERR! command "/usr/local/node/bin/node" "/apps/vuetest/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /apps/vuetest/node_modules/node-sass
gyp ERR! node -v v8.11.3
gyp ERR! node-gyp -v v3.7.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
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! 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! /root/.npm/_logs/2018-06-27T16_32_20_050Z-debug.log
```

package.json
```json
{
"name": "vuetest",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js"
},
"dependencies": {
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"sass-loader": "^7.0.3",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
```
...全文
1012 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ambit_tsai-微信 2018-06-28
  • 打赏
  • 举报
回复
看报错就是mkdir失败,看起来就是权限不够的样子。 算了,睡觉去,明天再来围观。
ambit_tsai-微信 2018-06-28
  • 打赏
  • 举报
回复
引用 3 楼 beimyy的回复:
引用 1 楼 ambit_tsai 的回复:
应该是权限不够,用root试试
我当前用户就是root
仔细一看还真是root账户
beimyy 2018-06-28
  • 打赏
  • 举报
回复
引用 2 楼 ambit_tsai 的回复:
[quote=引用 1 楼 ambit_tsai的回复:]应该是权限不够,用root试试

sudo npm install ......[/quote]
用sudo找不到命令
```shell
[root@vm172-31-48-7 vuetest]# sudo npm install node-sass --save-dev --registry=https://registry.npm.taobao.org
sudo: npm:找不到命令
```
beimyy 2018-06-28
  • 打赏
  • 举报
回复
引用 1 楼 ambit_tsai 的回复:
应该是权限不够,用root试试
我当前用户就是root
ambit_tsai-微信 2018-06-28
  • 打赏
  • 举报
回复
引用 1 楼 ambit_tsai的回复:
应该是权限不够,用root试试
sudo npm install ......
ambit_tsai-微信 2018-06-28
  • 打赏
  • 举报
回复
应该是权限不够,用root试试
beimyy 2018-06-28
  • 打赏
  • 举报
回复
通过配置npm解决

npm config set user 0
npm config set unsafe-perm true

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧