npm install 的时候报errno -4048 syscall unlink

今天开始写前端,于是上网找了个模板,尝试运行看看:这是Ngx-admin的帮助文档

我按照文档的提示,检查node.js以及npm的版本,分别是10和6,满足要求
接下来运行npm install命令(文档是cd和npm install一起的),结果报了如下错误:

npm WARN tarball tarball data for [email protected] (sha512-2kLhHvSAVbJ6QYVDxuySFp/+LfJxlYTYyPaOfwqydiFMAL9Wx7jzarfR1P4P6DFzLCZi4U4mv6EcZhH9BantKQ==) seems to be corrupted. Trying one more time.
npm ERR! code EPERM
npm ERR! syscall unlink
npm ERR! path D:\workspace\ManagerUI\ngx-admin\node_modules\.staging\echarts-44733145\dist\echarts.simple.min.js
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, unlink 'D:\workspace\ManagerUI\ngx-admin\node_modules\.staging\echarts-44733145\dist\echarts.simple.min.js'
npm ERR!  { [Error: EPERM: operation not permitted, unlink 'D:\workspace\ManagerUI\ngx-admin\node_modules\.staging\echarts-44733145\dist\echarts.simple.min.js']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, unlink 'D:\workspace\ManagerUI\ngx-admin\node_modules\.staging\echarts-44733145\dist\echarts.simple.min.js'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'unlink',
npm ERR!      path:
npm ERR!       'D:\\workspace\\ManagerUI\\ngx-admin\\node_modules\\.staging\\echarts-44733145\\dist\\echarts.simple.min.js' },
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, unlink \'D:\\workspace\\ManagerUI\\ngx-admin\\node_modules\\.staging\\echarts-44733145\\dist\\echarts.simple.min.js\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path:
npm ERR!    'D:\\workspace\\ManagerUI\\ngx-admin\\node_modules\\.staging\\echarts-44733145\\dist\\echarts.simple.min.js',
npm ERR!   parent: 'ngx-admin' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

这其中比较有用的几个词或提示是是

  • errno: -4048
  • syscall: ‘unlink’,
  • npm ERR! the command again as root/Administrator.

根据错误信息,我开始寻思解决

最后一句话的提示很明显:需要root权限

于是我切换成root权限再试了一次,结果没变,依旧是上面的错误

排除权限问题,回到上面两个提示

百度-4048错误,有好几种,找其中syscall: ‘unlink’,的

  • 网上的答案五花八门

比如:有个老外移除了npm-cache和npm文件,说it has helped…解决了不过我没试过,这两个文件都在C:\Users{用户名}\AppData\Roaming下,如果我的方法无法解决不妨试一试他的。网址在此

我的解决方法

unlink很容易让我联想起以前搭私人博客的时候,npm命令老是没反应(心酸),于是我翻了翻以前的博客(搭建私人博客踩过的坑)中npm install XXX没反应这一段,加了–registry=https://registry.npm.taobao.org,重新npm install 了一下(第一行就是完整命令):

D:\workspace\ManagerUI\ngx-admin>npm install --registry=https://registry.npm.taobao.org

> [email protected] install D:\workspace\ManagerUI\ngx-admin\node_modules\husky
> node ./bin/install.js

husky
setting up hooks
done


> [email protected] install D:\workspace\ManagerUI\ngx-admin\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://npm.taobao.org/mirrors/node-sass//v4.12.0/win32-x64-64_binding.node
Download complete  ] - :
Binary saved to D:\workspace\ManagerUI\ngx-admin\node_modules\node-sass\vendor\win32-x64-64\binding.node
Caching binary to C:\Users\YBJB\AppData\Roaming\npm-cache\node-sass\4.12.0\win32-x64-64_binding.node

> @angular/[email protected] postinstall D:\workspace\ManagerUI\ngx-admin\node_modules\@angular\cli
> node ./bin/postinstall/script.js

? Would you like to share anonymous usage data with the Angular Team at Google under
Google’s Privacy Policy at https://policies.google.com/privacy? For more details and
how to change this setting, see http://angular.io/analytics. Yes

Thank you for sharing anonymous usage data. If you change your mind, the following
command will disable this feature entirely:

    ng analytics off


> [email protected] postinstall D:\workspace\ManagerUI\ngx-admin\node_modules\node-sass
> node scripts/build.js

Binary found at D:\workspace\ManagerUI\ngx-admin\node_modules\node-sass\vendor\win32-x64-64\binding.node
Testing binary
Binary is fine
npm WARN rollback Rolling back [email protected] failed (this is probably harmless): EPERM: operation not permitted, rmdir 'D:\workspace\ManagerUI\ngx-admin\node_modules\sass\node_modules\fsevents\node_modules'
npm WARN rollback Rolling back [email protected] failed (this is probably harmless): EPERM: operation not permitted, rmdir 'D:\workspace\ManagerUI\ngx-admin\node_modules\@angular\compiler-cli\node_modules\fsevents'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\watchpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\sass\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\@angular\compiler-cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 2015 packages from 1233 contributors in 172.314s

D:\workspace\ManagerUI\ngx-admin>

成功安装后继续,验证是否可以本地启动


D:\workspace\ManagerUI\ngx-admin>npm start

> [email protected] start D:\workspace\ManagerUI\ngx-admin
> ng serve

                                                                                                                       p
Date: 2019-08-29T11:24:34.941Z
Hash: 3776ac5790d5a63adc32
Time: 100477ms
chunk {app-pages-pages-module} app-pages-pages-module.js, app-pages-pages-module.js.map (app-pages-pages-module) 16.6 MB  [rendered]
chunk {charts-charts-module} charts-charts-module.js, charts-charts-module.js.map (charts-charts-module) 950 kB  [rendered]
chunk {default~maps-maps-module~modal-overlays-modal-overlays-module} default~maps-maps-module~modal-overlays-modal-overlays-module.js, default~maps-maps-module~modal-overlays-modal-overlays-module.js.map (default~maps-maps-module~modal-overlays-modal-overlays-module) 13.9 kB  [rendered]
chunk {editors-editors-module} editors-editors-module.js, editors-editors-module.js.map (editors-editors-module) 583 kB  [rendered]
chunk {extra-components-extra-components-module} extra-components-extra-components-module.js, extra-components-extra-components-module.js.map (extra-components-extra-components-module) 3.2 MB  [rendered]
chunk {forms-forms-module} forms-forms-module.js, forms-forms-module.js.map (forms-forms-module) 566 kB  [rendered]
chunk {layout-layout-module} layout-layout-module.js, layout-layout-module.js.map (layout-layout-module) 851 kB  [rendered]
chunk {main} main.js, main.js.map (main) 1.55 MB [initial] [rendered]
chunk {maps-maps-module} maps-maps-module.js, maps-maps-module.js.map (maps-maps-module) 1.34 MB  [rendered]
chunk {modal-overlays-modal-overlays-module} modal-overlays-modal-overlays-module.js, modal-overlays-modal-overlays-module.js.map (modal-overlays-modal-overlays-module) 1.93 MB  [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 460 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 462 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 9.4 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 1.3 MB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 3.89 MB [initial] [rendered]
chunk {tables-tables-module} tables-tables-module.js, tables-tables-module.js.map (tables-tables-module) 1.36 MB  [rendered]
chunk {ui-features-ui-features-module} ui-features-ui-features-module.js, ui-features-ui-features-module.js.map (ui-features-ui-features-module) 872 kB  [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 6.48 MB [initial] [rendered]
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Compiled successfully.

npm install 的时候报errno -4048 syscall unlink_第1张图片

总结

  • 关于npm命令没有效果,很大可能是国内访问外国服务器的网速感人,之前报错,是在下载一个配置很长时间之后才出现的,再早些时候搭博客的时候根本就没反应~
  • 另外我还发现cmd中运行命令比git bash 中流畅不少

你可能感兴趣的:(#,前端基础)