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

NodeJS API项目本地构建报错:ENOENT: no such file or directory, lstat

NodeJS API构建失败问题排查与解决

问题详情

我用NodeJS开发了一个API应用,本地运行正常,但推送到Heroku时出现构建错误。本地执行yarn start build命令也报错,完整执行流程及输出如下:

nps is executing `build` : nps banner.build && nps config && nps lint && nps clean.dist && nps copy && nps copy.tmp && nps clean.tmp
nps is executing `banner.build` : ts-node --transpile-only ./commands/banner.ts build
  _           _ _     _ 
 | |__  _   _(_) | __| |
 | '_ \| | | | | |/ _` |
 | |_) | |_| | | | (_| |
 |_.__/ \__,_|_|_|\__,_|
                        

nps is executing `config` : ts-node --transpile-only ./commands/tsconfig.ts
nps is executing `lint` : tslint -c ./tslint.json ./src/**/*.ts --format stylish
nps is executing `clean.dist` : node node_modules/rimraf/bin.js ./dist
nps is executing `copy` : nps copy.public
nps is executing `copy.public` : copyfiles --up 1 ./src/public/* ./dist
nps is executing `copy.tmp` : ncp ./.tmp/src ./dist
There were errors during the copy.

错误提示:

Error: ENOENT: no such file or directory, lstat

已尝试的操作:

  • 清理缓存
  • 删除Node modules并重新安装
  • 升级所有依赖到最新版本

解决步骤

1. 定位缺失的核心目录

报错触发于ncp ./.tmp/src ./dist命令,说明.tmp/src目录不存在。先手动检查本地目录:

  • Mac/Linux执行ls -la .tmp,Windows执行dir .tmp,确认.tmp文件夹是否存在。
  • 若不存在,说明构建流程中生成.tmp/src的步骤缺失或执行失败。

2. 检查构建脚本逻辑

当前build流程顺序为:banner.build → config → lint → clean.dist → copy → copy.tmp → clean.tmp,问题出在copy.tmp前没有生成.tmp/src的环节:

  • 查看commands/tsconfig.ts或其他相关脚本,确认是否有将TypeScript编译到.tmp/src的逻辑,若有则检查该脚本是否执行成功。
  • 若没有生成.tmp/src的步骤,需在copy.tmp前添加TypeScript编译命令,比如用tsc将src目录文件编译到.tmp/src。

3. 调整构建顺序或脚本配置

  • 修改nps配置(通常在package.json或nps.config.js中),确保在copy.tmp之前执行生成.tmp/src的步骤。比如在build流程中加入nps compile,其中compile是专门编译TS到.tmp/src的脚本。
  • 若.tmp是临时目录被.gitignore忽略,无需修改忽略规则,重点保证本地构建时脚本能正常生成该目录。

4. 验证修复效果

手动删除.tmp和dist目录,重新执行yarn start build,确认每个步骤正常执行,.tmp/src生成后再完成copy.tmp操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 14:32:34