当我想要运行npm run dev
时,我正忙着学习Laravel并遇到问题
首先是一些背景信息:
执行步骤:
sudo composer create-project --prefer-dist laravel/laravel npmtest
sudo chmod -R 777 /var/www/npmtest
sudo composer install
sudo npm install
(已发现错误) sudo npm install
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
> node-sass@4.9.0 install /var/www/npmtest/node_modules/node-sass
> node scripts/install.js
Unable to save binary /var/www/npmtest/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/var/www/npmtest/node_modules/node-sass/vendor'
at Object.fs.mkdirSync (fs.js:885:18)
at sync (/var/www/npmtest/node_modules/mkdirp/index.js:71:13)
at Function.sync (/var/www/npmtest/node_modules/mkdirp/index.js:77:24)
at checkAndDownloadBinary (/var/www/npmtest/node_modules/node-sass/scripts/install.js:114:11)
at Object.<anonymous> (/var/www/npmtest/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: '/var/www/npmtest/node_modules/node-sass/vendor' }
> uglifyjs-webpack-plugin@0.4.6 postinstall /var/www/npmtest/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
> node-sass@4.9.0 postinstall /var/www/npmtest/node_modules/node-sass
> node scripts/build.js
Building: /usr/bin/node /var/www/npmtest/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/bin/node',
gyp verb cli '/var/www/npmtest/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.6.2
gyp info using node@8.10.0 | 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.15rc1\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.10.0
gyp verb command install [ '8.10.0' ]
gyp verb install input version string "8.10.0"
gyp verb install installing version: 8.10.0
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.10.0
gyp verb build dir attempting to create "build" dir: /var/www/npmtest/node_modules/node-sass/build
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/npmtest/node_modules/node-sass/build'
gyp ERR! System Linux 4.15.0-20-generic
gyp ERR! command "/usr/bin/node" "/var/www/npmtest/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/npmtest/node_modules/node-sass
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
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! /home/roge/.npm/_logs/2018-05-18T13_53_01_126Z-debug.log
由于我不知道如何处理错误,并注意到其中一些错过了节点模块的权限和权限,而不是777,可能是因为以root身份执行npm install
,我做了:
sudo chmod -R 777 /var/www/npmtest
再次sudo npm install
结果:
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
> node-sass@4.9.0 install /var/www/npmtest/node_modules/node-sass
> node scripts/install.js
Unable to save binary /var/www/npmtest/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/var/www/npmtest/node_modules/node-sass/vendor'
at Object.fs.mkdirSync (fs.js:885:18)
at sync (/var/www/npmtest/node_modules/mkdirp/index.js:71:13)
at Function.sync (/var/www/npmtest/node_modules/mkdirp/index.js:77:24)
at checkAndDownloadBinary (/var/www/npmtest/node_modules/node-sass/scripts/install.js:114:11)
at Object.<anonymous> (/var/www/npmtest/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: '/var/www/npmtest/node_modules/node-sass/vendor' }
> uglifyjs-webpack-plugin@0.4.6 postinstall /var/www/npmtest/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
> node-sass@4.9.0 postinstall /var/www/npmtest/node_modules/node-sass
> node scripts/build.js
Building: /usr/bin/node /var/www/npmtest/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/bin/node',
gyp verb cli '/var/www/npmtest/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.6.2
gyp info using node@8.10.0 | 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.15rc1\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.10.0
gyp verb command install [ '8.10.0' ]
gyp verb install input version string "8.10.0"
gyp verb install installing version: 8.10.0
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.10.0
gyp verb build dir attempting to create "build" dir: /var/www/npmtest/node_modules/node-sass/build
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/npmtest/node_modules/node-sass/build'
gyp ERR! System Linux 4.15.0-20-generic
gyp ERR! command "/usr/bin/node" "/var/www/npmtest/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/npmtest/node_modules/node-sass
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
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! /home/roge/.npm/_logs/2018-05-18T13_53_01_126Z-debug.log
sudo npm run dev
(并且没有sudo)什么不能解决问题结果:
> @ dev /var/www/npmtest
> npm run development
> @ development /var/www/npmtest
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
module.js:549
throw err;
^
Error: Cannot find module '/var/www/npmtest/node_modules/laravel-mix/setup/webpack.config.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at requireConfig (/var/www/npmtest/node_modules/webpack/bin/convert-argv.js:97:18)
at /var/www/npmtest/node_modules/webpack/bin/convert-argv.js:104:17
at Array.forEach (<anonymous>)
at module.exports (/var/www/npmtest/node_modules/webpack/bin/convert-argv.js:102:15)
at yargs.parse (/var/www/npmtest/node_modules/webpack/bin/webpack.js:171:41)
at Object.Yargs.self.parse (/var/www/npmtest/node_modules/yargs/yargs.js:533:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ development 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/roge/.npm/_logs/2018-05-18T14_01_02_924Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev 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/roge/.npm/_logs/2018-05-18T14_01_02_953Z-debug.log
谷歌几个小时后尝试: https://github.com/JeffreyWay/laravel-mix/issues/533和https://github.com/JeffreyWay/laravel-mix/issues/1072以及更多我不知道在哪里继续。
出于某种神奇的原因,npm run dev
在我的一个项目中工作。它是相同的Laravel版本,我真的不知道我在那里做了什么,而不是我试图开始工作的(多个)新项目......
我忘记了什么或错了吗?希望有人能帮助我!提前谢谢......
答案 0 :(得分:1)
我解决了同样的问题
udo apt-get install libpng-dev
npm install -g pngquant-bin