parcel-bundler/parcel · error · Error

failed to locate file ${originalPath}

Error message

failed to locate file ${originalPath}

What it means

Thrown by @parcel/transformer-stylus when neither Parcel's resolve() nor Stylus's built-in utils.find / utils.lookupIndex can locate an @import/@require target. The resolver chain first tries Parcel's resolve with the `stylus`/`style` package conditions; if that returns nothing it falls back to Stylus's native file finder across configured paths; if both fail it throws this generic message.

Source

Thrown at packages/transformers/stylus/src/StylusTransformer.js:194

        // checked so we invalidate the cache when they are created.
        let restore = patchNativeFS(asset.fs, nativeGlob);

        let paths = [
          ...new Set(
            (options.paths || []).concat(path.dirname(filepath || '.')),
          ),
        ];
        found = utils.find(importedPath, paths, filepath);
        if (!found) {
          found = utils.lookupIndex(originalPath, paths, filepath);
        }

        for (let invalidation of restore()) {
          asset.invalidateOnFileCreate(invalidation);
        }

        if (!found) {
          throw new Error('failed to locate file ' + originalPath);
        }
      }

      // Recursively process resolved files as well to get nested deps
      for (let resolved of found) {
        if (!seen.has(resolved)) {
          asset.invalidateOnFileChange(resolved);

          let code = await asset.fs.readFile(resolved, 'utf8');
          for (let [path, resolvedPath] of await getDependencies(
            code,
            resolved,
            asset,
            resolve,
            options,
            parcelOptions,
            nativeGlob,
            seen,

View on GitHub (pinned to 59484858a1)

Solutions

  1. Confirm the file exists at the expected path relative to the importing file.
  2. If importing from node_modules, install the package and use the bare specifier (Parcel will resolve with the stylus/style conditions).
  3. Add the directory containing the file to `paths` in .stylusrc or in the `stylus` key of package.json.
  4. If the path uses no extension, Stylus will try appending `.styl` — verify the basename matches exactly.

Example fix

// before: src/app.styl
@import 'theme/colors'
// file actually lives at src/styles/colors.styl

// after
@import '../styles/colors'
// or add to .stylusrc:
{ "paths": ["./src/styles"] }
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
function stylusImportResolves(importPath, fromFile, configPaths = []) {
  const dir = path.dirname(fromFile);
  const candidates = [
    path.resolve(dir, importPath),
    path.resolve(dir, importPath + '.styl'),
    ...configPaths.map(p => path.resolve(p, importPath)),
    ...configPaths.map(p => path.resolve(p, importPath + '.styl')),
  ];
  return candidates.find(c => fs.existsSync(c));
}

Prevention

When it happens

Trigger: A Stylus file contains `@import 'foo'` or `@require 'foo'` where 'foo' (and 'foo.styl') does not exist in any of: the current file's directory, the configured `paths` (from .stylusrc or stylus package key), or the Stylus `include css` search paths.

Common situations: Typo'd import path; importing from node_modules without the right package conditions; moving a .styl file and forgetting to update relative imports; missing optional `.styl` extension handling; package not installed in node_modules.

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/108f2cc653ff6fad. Report an issue: GitHub.