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

使用VSCode Azure App Service扩展部署Node.js/TS项目遇ENOENT错误求助

Node.js+TypeScript项目部署Azure部署槽遇ENOENT错误排查

我正尝试通过VSCode的Azure App Service扩展,将Node.js+TypeScript项目部署至Azure部署槽,但遇到错误:ENOENT: no such file or directory。项目目录结构见附图,package.json配置如下:

{
  "name": "otj_server_app",
  "version": "1.0.0",
  "description": "",
  "main": "build/src/index.js",
  "scripts": {
    "build_typescript": "tsc",
    "build_local": "cp config/config_local.json config/config.json",
    "build_dev": "cp config/config_dev.json config/config.json",
    "build_sit": "cp config/config_sit.json config/config.json",
    "build_prod": "cp config/config_prod.json config/config.json",
    "start": "tsc && nodemon build/src/index.js",
    "clean": "rimraf build",
    "build": "npm run clean && tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.20.0",
    "cors": "^2.8.5",
    "express": "^4.18.1",
    "express-session": "^1.17.3",
    "form-data": "^4.0.0",
    "formidable": "^2.0.1",
    "fs-extra": "^10.1.0",
    "https": "^1.0.0",
    "infosysta-typescript-core": "git+ssh://git@scm.infosysta.com:7999/ac/infosysta-typescript-core.git",
    "oauth": "^0.10.0",
    "random-string": "^0.2.0",
    "request-promise": "^4.2.6",
    "rimraf": "^5.0.0",
    "socket.io": "^2.4.1",
    "socket.io-client": "^2.3.0",
    "typescript": "^4.8.3"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.14",
    "@types/express-session": "^1.17.4",
    "nodemon": "^2.0.19"
  }
}

已尝试删除node_modules文件夹、package-lock.json后执行npm install重试,以及强制清理npm缓存(npm cache clean --force)后重复上述步骤,但问题仍未解决。

可能的原因及排查方向

  • 构建产物缺失或路径错误
    • 本地执行npm run build,确认是否成功生成build/src/index.js文件。若构建失败,部署时自然找不到入口文件。
    • 检查tsconfig.json的outDir配置是否指向build目录,配置错误会导致编译后的文件不在预期路径。
  • 配置文件未正确生成
    • 部署槽对应环境的配置复制脚本(如build_dev/build_sit)未执行,导致项目启动时找不到config/config.json。Azure默认可能只执行build脚本,需调整部署流程:要么在build脚本中加入对应环境的复制命令,要么在VSCode扩展的部署配置里指定预部署脚本。
  • 部署文件被误排除
    • 检查.gitignore或.deployment文件,确认是否误将build目录或config文件夹排除在外,导致这些关键文件未上传到Azure。
  • Azure启动命令配置错误
    • 确认部署槽的启动命令是否正确,比如是否设置为npm start或直接指向build/src/index.js。若使用Oryx自动构建,需确保它能正确识别项目的构建逻辑,必要时可添加oryx-manifest.toml自定义构建流程。
  • 私有依赖安装失败
    • 私有包infosysta-typescript-core在Azure环境下可能无法正常拉取,导致后续构建或启动失败。可以在本地模拟Azure的Linux环境(比如用Docker容器)执行npm install和npm run build,排查依赖安装问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 11:53:20