Paths Work Locally but Fail After Deployment: How to Troubleshoot

    Learn how to diagnose missing assets, failed file reads, and broken requests after deployment by separating filesystem paths, URLs, application routes, and build artifacts. This guide covers working directories, filename case, permissions, deployment prefixes, proxy rewrites, and release checks, with a practical troubleshooting sequence and pre-deployment checklist.

    Paths Work Locally but Fail After Deployment: How to Troubleshoot

    A page works locally, but after deployment, images, stylesheets, scripts, configuration files, or API requests fail with 404 errors, blank pages, or loading failures. This is a common problem in development and operations.

    The first assumption is often that a path contains a typo. In practice, the cause is usually more fundamental: the base used to resolve the path has changed, or the file is not where the runtime expects it to be.

    Working locally only proves that the code works with your current machine, startup directory, permissions, and development server behavior. Deployment can change all of these conditions at once.

    Instead of repeatedly changing ./ and ../, start with one question: What base is this path being resolved against? Separating filesystem paths, URL paths, application routes, and build artifact paths helps prevent fixes that merely hide the problem behind another coincidence.

    1. Distinguish Four Types of Paths

    The same path string can mean different things at different layers. At a minimum, distinguish these four categories:

    1. Filesystem paths
      Resolved by the server process when reading configuration, templates, uploads, or logs. They depend on the current working directory, entry file location, application root, mount points, and runtime user permissions.

    2. URL paths
      Resolved by the browser for images, stylesheets, scripts, and API requests. They depend on the current page URL, any HTML base element, the deployment prefix, and reverse proxy rules.

    3. Application routes
      Matched by server-side or client-side routing, such as /user/detail or /api/v1/list. Gateways may strip prefixes, rewrite paths, or normalize trailing slashes. A route is not a filesystem path.

    4. Build artifact paths
      Determined by the build and release process, including output directories, hashed filenames, and asset manifests. A development server may generate resources dynamically or provide fallbacks, while a production release contains only the files included in its build output.

    Many confusing failures come from mixing these layers. For example, a server may read configuration relative to its working directory, while a browser resolves an asset relative to the current page URL. An API URL may point to the site root even though the application is deployed under a subdirectory.

    2. Root Cause: The Working Directory Changed

    For server-side file operations, ./xxx and ../xxx usually refer to the process’s current working directory. They are not necessarily relative to the source file containing the code or to the project root.

    During local development, you may start the application from the project root, so ./config/app.json resolves correctly. After deployment, a system service, container entry point, or release script may start the process from another directory. The same relative path then points somewhere else.

    A fragile approach:

    1. // Depends on the current working directory and may fail when the startup directory changes
    2. config = readFile("./config/app.json")

    A more reliable approach uses an explicit anchor, such as the entry file directory, application root, or a configured application base directory:

    1. // Use the entry file directory as an anchor, then construct an absolute path
    2. entryDir = runtime.entryFileDirectory()
    3. appRoot = absolutePath(pathJoin(entryDir, ".."))
    4. configPath = absolutePath(pathJoin(appRoot, "config", "app.json"))
    5. if !fileExists(configPath):
    6. fail("Configuration file does not exist: " + configPath)
    7. assertReadable(configPath, "The runtime user must be able to read this file")

    Record the current working directory separately from the application root. At startup, log the working directory, entry file directory, resolved absolute configuration path, and runtime user. This makes an incorrect startup directory visible rather than leaving it to guesswork.

    3. Root Cause: Case Sensitivity and Hidden Filename Differences

    Some desktop environments use case-insensitive filesystems by default. A reference to logo.png may still open a file named Logo.PNG. On a case-sensitive production filesystem, the names must match exactly.

    This is easy to miss because the local environment tolerates the mismatch while production does not.

    Check more than the file extension. Directory names, capitalization, underscores, hyphens, spaces, and multiword filenames all matter:

    1. Local: assets/Images/Logo.PNG
    2. Production: assets/images/logo.png

    On a case-sensitive filesystem, these are different paths—not nearly identical ones.

    Character normalization can also matter. Accented or non-ASCII characters that look identical may have different underlying representations. Filenames containing spaces or special characters can introduce URL-encoding issues as well.

    A practical naming convention is to use lowercase ASCII letters, digits, hyphens, underscores, and periods wherever possible. Avoid spaces, inconsistent capitalization, and complex special characters.

    For larger projects, add automated checks before release. Compare resource references in code and pages against the release artifact inventory. Where possible, run smoke tests in a case-sensitive environment rather than relying exclusively on a local desktop filesystem.

    4. Root Cause: The File Exists, but the Runtime User Cannot Access It

    Ownership and permission problems are often mistaken for path problems. The path is correct and the file exists, but the service account cannot read it—or cannot traverse one of its parent directories.

    Checking the file’s permissions alone is not enough. Every directory in the path must allow the required traversal. A readable file can still be inaccessible if a parent directory blocks access.

    Common causes include:

    • Extracting a release package under a different owner.
    • Running the service under a different account from the build process.
    • Allowing writes to an upload directory without granting the required read access.
    • Switching a symlink to a new release directory whose permissions, or parent directory permissions, are incorrect.
    • Security policies or filesystem access controls denying the runtime user access.
    • Missing write permissions on log or cache directories, making a permission failure look like a configuration path error.

    Test access as the actual runtime user. Verify that the target file is readable, every parent directory is traversable, and upload or cache directories are writable where required.

    Do not solve this by granting unrestricted access to everyone. Follow the principle of least privilege and grant only the read, write, execute, or traversal permissions the service needs.

    5. Root Cause: The Deployment Prefix or URL Base Changed

    Local applications often run at the site root, /. In production, the application may be mounted under a subdirectory such as /app/. Root-relative and page-relative URLs behave differently in this situation.

    For example:

    1. Public deployment prefix: /app/
    2. Current page URL: /app/user/detail
    3. Resource reference: assets/logo.png
    4. Browser-resolved URL: /app/user/assets/logo.png
    5. Intended resource URL: /app/assets/logo.png

    Using /assets/logo.png does not necessarily fix the problem. A leading slash resolves from the site root, dropping the /app/ prefix.

    Page-relative paths are not always reliable either. As routes become deeper, their resolved resource URLs can move further from the intended location.

    Construct public URLs from a centralized public base:

    1. publicBase = normalizeBase(config.publicBase) // "/" for root deployment, "/app/" for subdirectory deployment
    2. logoUrl = joinUrl(publicBase, "assets/logo.png")

    Normalize trailing slashes as well. When used as a page base, /app and /app/ can produce different results for relative URLs. Redirect to a canonical form or construct URLs from an explicit base instead of relying on each page’s trailing-slash state.

    6. Root Cause: Gateway, Static Serving, and Routing Rules Disagree

    Production requests often pass through a gateway, reverse proxy, static file server, or application router before reaching the application process. Each layer can transform the path.

    For example, a gateway may strip a shared prefix, the static server may use a different document root, and the application may match routes using its own prefix. The result can be an API 404, an asset 404, or even a successful response containing the home page instead of the requested resource.

    Trace the path through each layer:

    1. Original browser request: /app/assets/logo.png
    2. Gateway forwarded path: /assets/logo.png
    3. Static directory mapping: public document root + /assets/logo.png
    4. Application route match: /assets/logo.png
    5. Runtime filesystem path: actual public root/assets/logo.png

    Listing each layer’s input and output makes it possible to identify whether the problem is the browser’s URL base, a proxy rewrite, the static document root, or application routing.

    Development server fallbacks deserve particular attention. Some development servers return the home page for unmatched paths, while production static servers do not. This can make a bad path appear to work locally.

    Single-page application route fallbacks should not apply unconditionally to scripts, stylesheets, or images. Otherwise, a missing asset returns HTML instead of a 404, causing content-type or loading errors and masking the original path problem.

    7. Root Cause: Production Artifacts Differ from Development Resources

    A development server may serve resources from memory, resolve paths automatically, expose files that are not included in the release directory, or generate assets directly from source.

    Production deployment typically copies only the build output. A referenced file may therefore be missing from the release package. Alternatively, the output may contain a content-hashed filename while the page still references an older or unhashed name.

    Check the release artifact inventory:

    • Does the target file actually exist in the deployed output?
    • Does the reference match the file path’s capitalization exactly?
    • Does the page reference the built, hashed filename or the source filename?
    • Does the asset manifest match the actual build output?
    • Have release exclusion rules omitted directories containing required files?
    • Does environment configuration point assets to a different public base?
    • If assets moved to object storage or a content delivery network, are the public prefix, object key capitalization, access permissions, and caching policies correct?

    Do not treat object storage or a CDN as though it were a local directory. Object keys are generally not a traversable filesystem directory tree. Public URLs, access policies, and cache controls are configuration-dependent.

    What looks like a path failure may therefore be either a nonexistent resource or an access-policy denial.

    8. A Practical Troubleshooting Sequence

    When paths work locally but fail after deployment, investigate in this order.

    1. Capture the Complete Failed Request

    Record the full resource URL, response status, response source, and page route. Determine whether the failure is a missing file, insufficient permissions, a proxy error, or a response containing the wrong content.

    2. Log the Runtime Context

    Record the current working directory, entry file directory, application root, resolved absolute file path, and runtime user.

    Do not log only the original relative path. Log the final resolved location.

    3. Verify File Existence and Exact Filename Matching

    Compare the reference with the release artifact inventory. Check directory levels, filenames, extensions, capitalization, and special characters.

    Do not assume that a path is correct because it worked on a case-insensitive local filesystem.

    4. Check Permissions as the Runtime User

    Verify file readability, traversal permissions on every parent directory, and write access for directories that require it.

    For symlink-based releases, inspect the real directory targeted by the link as well.

    5. Validate the Public URL Base

    Confirm whether the application is deployed at the site root or under a subdirectory. Check trailing-slash normalization, root-relative references, and whether resource URLs are constructed from a consistent base.

    6. Inspect Gateway and Routing Rewrites

    Compare paths across the browser, gateway, static server, application router, and runtime filesystem. Confirm that every transformation matches the intended deployment configuration.

    7. Compare Development and Release Behavior

    Check artifact completeness and manifest consistency. Determine whether the development server is hiding invalid paths or whether static asset requests are incorrectly falling back to the home page.

    8. Run Regression Checks After the Fix

    At minimum, test:

    • The home page and deep routes.
    • Root and subdirectory deployments.
    • URLs with and without trailing slashes.
    • A case-sensitive environment.
    • A restricted runtime user.

    9. Prevent Recurrence by Making Path Bases Explicit

    A reliable long-term solution is to make filesystem anchors and URL bases explicit rather than relying on deployment-time assumptions.

    • Anchor filesystem operations to the application root, entry file directory, or another explicit directory instead of the startup working directory.
    • Centralize path joining rather than manually assembling chains of ../.
    • Validate the existence and required read or write access of configuration files, templates, upload directories, and log directories at startup.
    • Construct public URLs from a public base plus a resource-relative path, with deployment prefixes supplied through configuration.
    • Use consistent lowercase ASCII resource names, reserving case-sensitive naming for situations that require it.
    • Apply the same artifact checks in development, testing, staging, and production.
    • Document reverse proxy, static serving, and application routing prefix rules, and cover them with automated smoke tests.
    • Log both request URLs and resolved absolute filesystem paths where applicable to support cross-layer diagnosis.
    • Probe critical resources after release and monitor unusual increases in 404 responses, 403 responses, and resource-loading failures.
    • Avoid hiding problems with world-writable permissions or unconditional home-page fallbacks.

    10. Pre-Deployment Checklist

    Before releasing, confirm the following:

    • Which directory starts the service process? Does the application still work when started from another directory?
    • Are critical filesystem paths anchored to explicit directories?
    • Does the release package contain every required file, with capitalization matching its references?
    • Can the runtime user read the files and traverse all parent directories?
    • Is the application deployed at the root or under a subdirectory? Is its public base configured correctly?
    • Are root-relative and page-relative URLs mixed? Do asset references still work on deep routes?
    • Does the gateway strip prefixes or rewrite paths? Is the static document root correct?
    • Is the development server masking missing files with automatic fallbacks?
    • Do build artifacts use hashed filenames, and do page references come from the current asset manifest?
    • Are public paths and access policies consistent across object storage, CDNs, and reverse proxies?
    • Have smoke tests covered a case-sensitive environment, subdirectory deployment, and a restricted runtime user?

    Conclusion

    Paths that work locally but fail after deployment are usually not just a matter of an incorrect string. They reflect changes in runtime conditions, path-resolution bases, or the release process.

    First identify the base used to resolve the failing path. Then separate filesystem paths, URLs, application routes, and build artifacts. Check working directories, filename case, permissions, deployment prefixes, proxy rewrites, and release contents in sequence.

    This approach is generally more effective than repeatedly adjusting ./ and ../. Explicit bases, centralized path construction, startup validation, and post-release regression checks turn paths from something that happens to work into something you can verify.