在 Debian 上“JS 日志频繁报错”通常不是 Debian 本身的问题,而是运行环境、依赖、代码或配置导致的。下面按最常见原因 → 排查方法 → 解决建议说明。
Debian 默认仓库里的 Node 版本往往偏旧。
表现
SyntaxErrorexports is not defined排查
node -v
对比项目 package.json 要求的版本:
"engines": {
"node": ">=18"
}
解决
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
表现
Cannot find moduleMODULE_NOT_FOUND排查
rm -rf node_modules package-lock.json
npm install
如用 yarn:
rm -rf node_modules yarn.lock
yarn install
表现
EACCESpermission denied原因
sudo npm -g 安装解决 不要用 sudo 装全局包:
npm config set prefix ~/.npm
应用目录权限:
chown -R appuser:appuser /var/www/app
表现
code=exited, status=1排查
journalctl -u your-js-service -f
常见错误:
NODE_ENV 未设置Debian 小内存机器常见。
表现
排查
dmesg | grep -i oom
free -h
解决
--max-old-space-size表现
常见原因
排查 nginx
include /etc/nginx/mime.types;
journalctl -u 你的服务 -n 100 --no-pager
node -v
npm -v
whoami
node app.js
你可以直接贴:
cat /etc/os-release)我可以直接帮你定位是哪一类问题,并给具体命令。