首页 > 解决方案 > 安装 node-sass 目录时 Ionic 教程失败

问题描述

我正在尝试通过运行以下命令在我的系统上运行 Ionic 教程(详见他们的文档中的教程页面

sudo ionic start MyIonicProject tutorial

但是,本教程在尝试在 MyIonicProject 中构建 node-sass 目录时总是失败:

gyp verb build dir attempting to create "build" dir: /Users/macdad/MyIonicProject/node_modules/node-sass/build
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/macdad/MyIonicProject/node_modules/node-sass/build'
gyp ERR! System Darwin 17.5.0
gyp ERR! command "/usr/local/bin/node" "/Users/macdad/MyIonicProject/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/macdad/MyIonicProject/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 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/macdad/.npm/_logs/2018-08-02T01_58_32_378Z-debug.log
[ERROR] An error occurred while running subprocess npm.

        npm i exited with exit code 1.

        Re-running this command with the --verbose flag may provide more 
        information.

当它尝试在node-sass/build目录中构建时,权限被拒绝 - 但是如何在尚不存在的目录上设置权限?调用 mkdir 时,较早的错误会输出以下内容:

Error: EACCES: permission denied, mkdir '/Users/imacuser/MyIonicProject/node_modules/node-sass/vendor'

父目录确实具有读/写权限。我在网上看到这个问题有不同的变体,但我找不到任何明确的答案。当您无法运行主要教程时,很难学习框架。感谢您可以在此处为新手提供的任何帮助。

编辑:在对所有随附项目应用读/写权限后,添加@ZearaeZ 建议的两个命令的完整结果。构建仍然失败:

MacBook-Pro-6:~ macdad$ sudo npm rebuild node-sass --force
npm WARN using --force I sure hope you know what you are doing.
MacBook-Pro-6:~ macdad$ sudo ionic start MyIonicProject
? ./MyIonicProject exists. Overwrite? Yes

Let's pick the perfect starter template! 

Starter templates are ready-to-go Ionic apps that come packed with everything 
you need to build your app. To bypass this prompt next time, supply template, 
the second argument to ionic start.

? Starter template: tabs
✔ Preparing directory ./MyIonicProject - done!
✔ Downloading and extracting tabs starter - done!
? Integrate your new app with Cordova to target native iOS and Android? Yes
> ionic integrations enable cordova --quiet
✔ Downloading integration cordova - done!
✔ Copying integrations files to project - done!
[OK] Integration cordova added!

Installing dependencies may take several minutes.

     ✨   IONIC  DEVAPP   ✨

 Speed up development with the Ionic DevApp, our fast, on-device testing mobile app

  -     Test on iOS and Android without Native SDKs
  -     LiveReload for instant style and JS updates

 -->    Install DevApp: https://bitly/ionic-dev-app    <--

────────────────────────────────────────────────────────────

> npm i
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.

> fsevents@1.2.4 install /Users/macdad/MyIonicProject/node_modules/fsevents
> node install

[fsevents] Success: "/Users/macdad/MyIonicProject/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> node-sass@4.9.0 install /Users/macdad/MyIonicProject/node_modules/node-sass
> node scripts/install.js

Unable to save binary /Users/macdad/MyIonicProject/node_modules/node-sass/vendor/darwin-x64-57 : { Error: EACCES: permission denied, mkdir '/Users/macdad/MyIonicProject/node_modules/node-sass/vendor'
    at Object.fs.mkdirSync (fs.js:885:18)
    at sync (/Users/macdad/MyIonicProject/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/Users/macdad/MyIonicProject/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/Users/macdad/MyIonicProject/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/Users/macdad/MyIonicProject/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: '/Users/macdad/MyIonicProject/node_modules/node-sass/vendor' }

> uglifyjs-webpack-plugin@0.4.6 postinstall /Users/macdad/MyIonicProject/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> node-sass@4.9.0 postinstall /Users/macdad/MyIonicProject/node_modules/node-sass
> node scripts/build.js

Building: /usr/local/bin/node /Users/macdad/MyIonicProject/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/bin/node',
gyp verb cli   '/Users/macdad/MyIonicProject/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.8.0
gyp info using node@8.11.3 | darwin | 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` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/macdad/MyIonicProject/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/macdad/MyIonicProject/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/macdad/MyIonicProject/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/macdad/MyIonicProject/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/macdad/MyIonicProject/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/macdad/MyIonicProject/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:152:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/macdad/MyIonicProject/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/macdad/MyIonicProject/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/macdad/MyIonicProject/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/macdad/MyIonicProject/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/macdad/MyIonicProject/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/macdad/MyIonicProject/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:152:21)
gyp verb `which` failed   stack: 'Error: not found: python2\n    at getNotFoundError (/Users/macdad/MyIonicProject/node_modules/which/which.js:13:12)\n    at F (/Users/macdad/MyIonicProject/node_modules/which/which.js:68:19)\n    at E (/Users/macdad/MyIonicProject/node_modules/which/which.js:80:29)\n    at /Users/macdad/MyIonicProject/node_modules/which/which.js:89:16\n    at /Users/macdad/MyIonicProject/node_modules/isexe/index.js:42:5\n    at /Users/macdad/MyIonicProject/node_modules/isexe/mode.js:8:5\n    at FSReqWrap.oncomplete (fs.js:152:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp verb check python version `/usr/bin/python -c "import sys; print "2.7.10
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
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: /Users/macdad/MyIonicProject/node_modules/node-sass/build
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/macdad/MyIonicProject/node_modules/node-sass/build'
gyp ERR! System Darwin 17.5.0
gyp ERR! command "/usr/local/bin/node" "/Users/macdad/MyIonicProject/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/macdad/MyIonicProject/node_modules/node-sass
gyp ERR! node -v v8.11.3
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/macdad/.npm/_logs/2018-08-09T13_25_52_106Z-debug.log
[ERROR] An error occurred while running subprocess npm.

        npm i exited with exit code 1.

        Re-running this command with the --verbose flag may provide more 
        information.

正如我所建议的那样,我不能对该目录拥有权限是有道理的,因为该node-sass目录是在运行时创建的,如果它没有自动读/写权限,那么如果它们不存在就很难添加它们.

标签: ionic-frameworksass

解决方案


首先,您需要为用户和组分配权限。

  1. 选择磁盘、文件夹或文件,然后选取“文件”>“显示简介”。

  2. 单击锁定图标将其解锁,然后输入管理员名称和密码。

  3. 点按“名称”栏中的用户或群组,然后从弹出式菜单中选取权限设置并授予读取和写入权限。

  4. 单击“操作”弹出菜单(Crog 图标),然后选择“应用于封闭项目”。</p>

向您的目录应用权限后在您的项目目录中运行此命令。

sudo npm rebuild node-sass --force

它将在您的项目目录中强制重建 node-sass。


推荐阅读