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

如何在Heroku上运行npm包命令?node-mongo-seeds执行报错

Fixing "command not found" for seed on Heroku Dyno (node-mongo-seeds)

Hey there, I’ve run into this exact issue before when deploying Express apps with node-mongo-seeds to Heroku. Let’s break down the most likely causes and how to fix them step by step:

1. Make sure node-mongo-seeds is in your dependencies (not devDependencies)

Heroku skips installing devDependencies by default when deploying your app. If you installed it with --save-dev, it won’t be present on the dyno at all.

  • Fix: Reinstall the package as a production dependency:
    npm install node-mongo-seeds --save
    
  • Commit the updated package.json and package-lock.json to Git, then push to Heroku:
    git add package.json package-lock.json
    git commit -m "Move node-mongo-seeds to production dependencies"
    git push heroku main
    

2. Use npm scripts to run the seed command

Directly typing seed in the dyno might fail because the package’s binary isn’t added to the system PATH. The reliable way to run it is via an npm script defined in your package.json:

  • Add this to your scripts section:
    "scripts": {
      // ... your existing scripts (like start, test)
      "seed": "seed"
    }
    
  • After deploying the updated package.json, connect to the dyno via SSH and run:
    npm run seed
    

If the direct seed call still doesn’t work in the script, reference the binary explicitly:

"seed": "node ./node_modules/node-mongo-seeds/bin/seed.js"

3. Temporary fix: Install the package globally in the dyno

If you need a quick one-off seed run and don’t want to redeploy, you can install node-mongo-seeds globally inside the dyno (note: this will disappear when the dyno restarts):

  • After SSH-ing into the dyno, run:
    npm install -g node-mongo-seeds
    
  • Now you should be able to run the seed command directly.

4. Verify your MongoDB connection config

Once the command is found, double-check that your Heroku environment variables have the correct MongoDB connection string (usually MONGODB_URI). node-mongo-seeds relies on this to connect to your database, so an incorrect config might throw errors even after fixing the "command not found" issue.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:14:18