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

Nest.js出现ENOENT错误:找不到文件或目录,无法打开'./push-service-account.json'的解决方案咨询

Fixing ENOENT Error for './push-service-account.json' in Nest.js (Without Deleting package-lock.json)

Hey there, I get that dealing with ENOENT errors when your app can't find a critical file is super frustrating—especially when you can't just delete package-lock.json because you rely on npm ci. Let's walk through targeted solutions that fit your Node 12.22.12 / npm 6.14.16 setup:

  • Double-check the file path and location
    First, make 100% sure push-service-account.json actually exists where your code is looking for it. The error points to ./push-service-account.json, which means it expects the file in the current working directory where you launch your Nest.js app.

    • If you run the app from a subfolder (like src/ instead of the project root), the relative path breaks. Either run the app from the project root, or adjust the path in your code to be absolute using Node's path module: path.resolve(__dirname, '../push-service-account.json') (where __dirname refers to the current file's directory).
    • Verify the filename is spelled perfectly—case sensitivity matters on Linux/macOS, so Push-Service-Account.json won't match the lowercase path in your error.
  • Ensure the file isn't gitignored or missing from your environment
    Sometimes service account files get accidentally added to .gitignore. Check your .gitignore to confirm push-service-account.json isn't listed. If it was ignored, either add it to your repo (if safe) or manually copy it to your development/deployment environment.

    • For CI/CD pipelines using npm ci, make sure the file is either included in the repo or injected as a secure asset during the pipeline—npm ci only manages dependencies, not project-specific files like this.
  • Check your npm script's working directory
    If you start your app via an npm script (e.g., npm run start), the working directory might not be what you expect. For example, a script like cd src && nest start will make your app look for the JSON file in src/ instead of the project root.

    • Edit your package.json scripts to run the app from the correct directory, or switch to absolute paths in your code as mentioned earlier.
  • Verify file permissions (Linux/macOS)
    On Unix-based systems, even if the file exists, your Node process might lack read access. Run ls -l push-service-account.json in your project root to check permissions. If needed, run chmod 644 push-service-account.json to grant read access to the file.

  • Clear the npm cache (no impact on package-lock.json)
    Don't worry—clearing the npm cache won't touch your package-lock.json, and sometimes cached files can cause unexpected path quirks. Run npm cache clean --force, then re-run npm ci to ensure dependencies are installed correctly. Since npm ci strictly follows your lock file, this is totally safe.

These steps should cover the most common causes without requiring you to delete your package-lock.json. Remember, npm ci only manages dependencies—it doesn't handle missing project assets like your service account file, so the fix almost always boils down to ensuring the file is in the right place and your code references it correctly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 15:22:49