【问题标题】:npm ERR! code Z_BUF_ERROR when installnpm 错误!安装时代码 Z_BUF_ERROR
【发布时间】:2018-07-22 05:45:31
【问题描述】:

在我的服务器(CentOS 7.2)中安装依赖项:

npm install 

但我得到以下错误:

npm ERR! code Z_BUF_ERROR
npm ERR! errno -5
npm ERR! unexpected end of file

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-02-11T21_03_20_261Z-debug.log

/root/.npm/_logs/2018-02-11T21_03_20_261Z-debug.log,信息如下:

10234 verbose bundle EBUNDLEOVERRIDE: Replacing npm@1.4.29's bundled version of readable-stream with readable-stream@1.0.34.
10235 verbose unlock done using /root/.npm/_locks/staging-ace74a3b0cf47932.lock for /home/ubuntu/source_code_web/vue_admin_site/node_modules/.staging
10236 warn The package iview is included as both a dev and production dependency.
10237 warn npm@1.4.29 had bundled packages that do not match the required version(s). They have been replaced with non-bundled versions.
10238 verbose type OperationalError
10239 verbose stack Error: unexpected end of file
10239 verbose stack     at Gunzip.zlibOnError (zlib.js:152:15)
10240 verbose cwd /home/ubuntu/source_code_web/vue_admin_site
10241 verbose Linux 3.10.0-327.el7.x86_64
10242 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
10243 verbose node v8.4.0
10244 verbose npm  v5.3.0
10245 error code Z_BUF_ERROR
10246 error errno -5
10247 error unexpected end of file
10248 verbose exit [ -5, true ]

我试过用:

npm cache clean

清理 npm,但失败:

npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
npm ERR! 
npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-02-11T21_13_51_943Z-debug.log

【问题讨论】:

    标签: node.js


    【解决方案1】:

    按照 npm GitHub 中的建议

    Node 8.9.0+(和 9+)修复了流提前终止的问题 在某些情况下。如果您收到此错误,请升级到 8.9。

    所以你可以尝试更新你的节点和 npm

    【讨论】:

      【解决方案2】:

      最后,我删除了node_modules

      rm -rf node_modules
      

      并删除了package-lock.json
      然后重新安装:

      npm install 
      

      它对我有用。

      【讨论】:

        【解决方案3】:

        尝试使用命令npm cache clean --force 清理缓存,然后重试您的 npm 安装。

        【讨论】:

        • 我们也有这个问题。清除缓存修复它。但它在后续构建中不断中断。你知道根本问题是什么吗?
        • 在我的情况下,由于外部 api 的错误导入,依赖关系相互覆盖。
        • 这似乎也对我有用,但只是为了记录:我还从我的.npmrc 中删除了package-lock-false。我不确定这或清理缓存是否真的解决了我的问题。我的 npm 在 Windows 上是 6.4.1
        【解决方案4】:

        在我的情况下,列出的解决方案都没有帮助。我通过手动删除缓存文件夹解决了这个问题:

        rm -rf ~/.npm/_cacache
        

        或者如果npm 安装在根文件夹中:

        sudo rm -rf /root/.npm/_cacache
        

        【讨论】:

          【解决方案5】:
          1. “npm 缓存清理 --force”
          2. “npm 缓存验证”

          以下步骤帮助了我!! :-)

          如果问题仍然存在:“npm i npm”

          【讨论】:

          • 它对我有用,如果前 2 步失败,不要忘记执行 npm i npm。 :)
          • 谢谢,我只穿了第一条线。
          【解决方案6】:

          我在 Windows 10 上尝试了这个,唯一对我有用的解决方案是通过提供更新 npm

          npm install npm@latest -g

          【讨论】:

          • 这解决了我的问题,而无需删除缓存或 node_modules 目录
          • 经过多次尝试,甚至来自 GitHub 和 StackOverflow 的其他答案,这个解决方案终于奏效了。此外,yarn add 能够为我安装包,但它没有将其添加到环境变量中。
          【解决方案7】:

          npm install --cache /tmp/empty-cache

          这对我有用

          【讨论】:

            【解决方案8】:
            1. 网络导致模块下载失败

            2. 安装一个淘宝镜像就可以了:
              npm install -g cnpm -- registry-https://registry.npm.taobao.org

            3. cnpm install egg -- save

            【讨论】:

              【解决方案9】:

              在尝试了与 npm 相关的所有操作后,问题仍然存在,这可能是由于“.apm”文件夹中一些不需要的缓存被删除造成的。 请按照以下步骤操作。

              1. 转到 -> C:\Users\Your_Username\.atom\.apm\_cacache
              2. 删除所有文件(tmp、内容、索引等)
              3. 再次尝试通过命令或原子安装包。

              这可能对你有用。 :-)

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2019-05-10
                • 1970-01-01
                • 2019-08-20
                • 2016-05-03
                • 2018-09-03
                • 1970-01-01
                • 2014-08-20
                相关资源
                最近更新 更多