You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SvelteKit(Node Adapter)直接启动正常,Systemd服务启动报错

SvelteKit部署问题:直接执行正常,systemd/crontab启动报语法错误

我正尝试将SvelteKit应用部署到Ubuntu 22.04.2 LTS服务器,实现自动启动与重启。以root用户直接执行node index.js时应用运行完全正常,但通过systemd服务或crontab启动时,errors.log中出现如下语法错误:

SyntaxError: Unexpected token '?'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)
file:///*path-to-app*/handler.js:768
    const DOMException = globalThis.DOMException ?? (() => {

我的systemd服务文件位于/lib/systemd/system/,内容如下:

[Unit]
Description = *description*

[Service]
Type           = simple
User           = root
Group          = root
LimitNOFILE    = 4096
Restart        = always
RestartSec     = 10s
StandardOutput = append:/*path-to-app*/logs.log
StandardError  = append:/*path-to-app*/errors.log
ExecStart      = node /*path-to-app*/index.js

[Install]
WantedBy = multi-user.target

已做排查:

  • 服务器仅安装Node.js 18.14.2版本,排除旧版Node的问题
  • 已在项目package.json中添加"type": "module"
  • 用最新版SvelteKit和Node适配器构建空骨架项目,仍出现相同错误

请问为何同一用户执行同一命令,直接运行和通过systemd/crontab启动会有不同结果?


内容的提问来源于stack exchange,提问作者user20343025

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 08:23:17