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

在Cyclic.sh部署仓库子目录的Node.js TypeScript应用遇问题求助

问题:Cyclic.sh部署仓库子目录中的Node.js TypeScript应用失败,提示找不到dist/server.js

环境配置信息

  • Cyclic高级构建选项:

    • Runtime: Node 18.12.1
    • Root Path: /lol-pickem-api
    • Output Path: lol-pickem-api/dist
  • /lol-pickem-api/package.json:

"main": "server.js",
  "scripts": {
    "build": "tsc --build",
    "build:watch": "tsc --watch",
    "start": "node dist/server.js",
    "start:watch": "rm -rf \"../dist/*\" && tsc-watch --onSuccess \"node -r source-map-support/register .\"",
    "debug": "rm -rf \"../dist/*\" && tsc-watch --onSuccess \"node --inspect -r source-map-support/register .\""
  },
  • /lol-pickem-api/tsconfig.json:
{
  "compilerOptions": {
    "sourceMap": true,
    "target": "es6",
    "module": "commonjs",
    "outDir": "./dist",
    "baseUrl": "./src",
    "esModuleInterop": true,
    "resolveJsonModule": true
  },
  "include": ["src/**/*.ts", "./package.json"],
  "exclude": ["node_modules"]
}
  • 核心报错信息:
Error: Cannot find module '/var/task/dist/server.js'
ERROR: Failed to run "npm run start". Start script defined in package.json:
            "scripts": {
                "start":  "node dist/server.js"
                 ...
Exited with code: 1

解决方案

1. 强制启动前执行构建

Cyclic默认可能不会自动触发TS编译,修改start脚本,先执行构建再启动服务:

"start": "npm run build && node dist/server.js"

2. 修正Cyclic的Output Path配置

当前Root Path已设为/lol-pickem-api,Output Path应相对该目录设置,改为dist即可,无需带前缀lol-pickem-api/。

3. 调整package.json的main字段

将main字段指向编译后的入口文件,确保Node能正确识别:

"main": "dist/server.js"

4. 本地验证编译流程

在本地执行cd lol-pickem-api && npm run build,检查是否生成了dist/server.js,同时确认src目录下存在server.ts入口文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 12:36:03