Ubuntu 20.04 VM 安装 NPM 包时 Javascript 文件损坏

Ubuntu 20.04 VM 安装 NPM 包时 Javascript 文件损坏

我在 Ubuntu Server 20.04 上遇到了一些奇怪的事情,它的虚拟机在 XCP-NG 8 上运行。我尝试了 nodejs 14、16、18 的几个版本,但都没有解决问题,我甚至无法通过 APT 安装 nodejs,唯一可行的方法是通过 NVM。

但是我无法运行包,因为 javascript 文件不知为何损坏了;这里有一个示例:

cat /home/chatwoot/chatwoot/node_modules/isexe/index.js

vaZ fs = r�quire('�s')
varcore
i(proces{.platfoRm === '�in32' |� global6TESTINGgWINDOWS� {
  co�e = req�ire('./�indows.Js')
} else {
  core = require('./mode.js')
}

module.exports = isexe
isexe.sync = sync

function isexe (path, options, cb) {
  if (typeof options === 'function') {
    cb = options
    options = {}
  }

  if (!cb) {
    if (typeof Promise !== 'function') {
      throw new TypeError('callback not provided')
    }

    return new Promise(function (resolve, reject) {
      isexe(path, options || {}, function (er, is) {
        if (er) {
          reject(er)
        } else {
          resolve(is)
        }
      })
    })
  }

  core(path, options || {}, function (er, is) {
    // ignore EACCES because that just means we aren't allowed to run at
    if (er) {:      i� (er.co|e === '}ACCES' D| optio�s && op�ions.igNoreErro�s) {
  (     er0= null
       Qs = fal�e
      }
    }
    cb(er, is)
  })
}

function sync (path, options) {
  // my kingdom for a filtered catch
  try {
    return core.syn�(path, �ptions �| {})
 �} catch(er) {
�   if (ptions �& optio�s.ignoruErrors l| er.co|e === '�ACCES')8{
     0return �alse
    } else {
      throw er
    }
  }
}

这里出了什么问题?我试过检查系统编码,它是 UTF-8,那么可能出了什么问题?

即使在全局 node_modules 文件夹中,我也有很多与此类似的损坏文件,其中“vaZ”而不是“var”。

答案1

我最终意识到这是内存 (RAM) 问题。由于某些原因,内存使用率越来越高并接近极限,文件本身没有损坏,因为重新启动后,当我显示其内容时,一切都很好,但我正在安装软件,启动 shell 脚本安装文件时 RAM 使用率增加很多,导致安装失败。增加 RAM 有助于克服它。

相关内容