Direct Answer
Yes, Replit prioritizes the run field in replit.json (or the legacy .replit) over any package.json scripts. If run is absent, Replit infers a command heuristically (for example npm start or the first script in package.json), and that inference can change between Replit versions.
Confirmed Behavior
- Run field precedence: The
run value is the single source of truth for the Repl’s “Run” button and for Replit Deployments. Local package.json scripts are ignored unless run explicitly invokes them.
- Runtime version pinning: Replit supplies a fixed Node, Python, or other runtime per language in its base images. The active version is visible in the Repl Console → Environment tab. Local version managers (
nvm, pyenv) have no effect inside the Repl.
- Environment variables: Secrets configured in the Repl’s Secrets tab are injected at runtime and override any
.env file committed to the repository. Local development must replicate the same variables via a local .env or shell export.
- Deployment pipeline difference: Replit Deployments (Autoscale/Reserved VM) use a separate build pipeline. A command that works in the development Repl can fail in Deployment if dependencies or build steps differ.
Likely Explanation for Mismatch
Your local start script (e.g., npm run dev or node src/index.js) works because your local environment matches the intended runtime, environment variables, and working directory. In Replit, the heuristic fallback may pick npm start (which could be a build script) or a different entry point, and the pinned runtime version may differ from your local Node version. Secrets missing in the Repl will cause runtime failures even if the command itself is correct.
Alignment Steps (Minimal Set)
- Open
replit.json (create it if missing) and set the run field to the exact command that works locally, for example:
{
"run": "node src/index.js"
}
- Lock the runtime version in the same file where supported:
{
"run": "node src/index.js",
"languageVersion": "20" // Node 20.x
}
For Python use pythonVersion": "3.11".
- Copy every environment variable your local start command depends on into the Repl’s Secrets tab (key/value pairs). Do not commit real credentials to
.env.
- Verify in the Repl Console:
node --version # or python --version
cat replit.json # confirm run field
printenv | grep MY_VAR # confirm secret injection
- Trigger a test Deployment and inspect the build logs to confirm the detected run command and runtime version match your expectations.
One Diagnostic Detail Needed
What is the exact command you run locally (including any flags or environment variable prefixes)? If it contains shell-specific syntax (e.g., NODE_ENV=production node ...), Replit’s non-interactive shell may require a different form (e.g., a wrapper script or cross-env). Provide that command and I can confirm whether a wrapper is needed.
Verification Checklist
- Repl Console shows the expected runtime version.
- Run button tooltip displays your exact
run command.
- Deployment build logs show the same command and version.
- Adding a temporary
echo $MY_VAR to the run command prints the secret value in both dev Repl and Deployment logs.
Note: Replit’s inference logic and default runtime versions can change without notice. Always verify the active version in the Repl Console before assuming parity. Custom Nix channels or Dockerfiles add maintenance overhead and may break when Replit updates its base images.