parcel-bundler/parcel · error · Error

Yarn failed to install modules: ${e.message}

Error message

Yarn failed to install modules: ${e.message}

What it means

Thrown by the Yarn package installer when the yarn install subprocess fails (promiseFromProcess rejects). The error message concatenates the caught exception's message. Yarn's stderr output is processed in a success-path loop (logging each line via the Parcel logger) but is not included in the thrown error message — only the process rejection reason is captured.

Source

Thrown at packages/core/package-manager/src/Yarn.js:148

              origin: '@parcel/package-manager',
              message: prefix(message.data),
            });
            return;
          case 'error':
            logger.error({
              origin: '@parcel/package-manager',
              message: prefix(message.data),
            });
            return;
          default:
          // ignore
        }
      });

    try {
      return await promiseFromProcess(installProcess);
    } catch (e) {
      throw new Error('Yarn failed to install modules:' + e.message);
    }
  }
}

function prefix(message: string): string {
  return 'yarn: ' + message;
}

registerSerializableClass(`${pkg.version}:Yarn`, Yarn);

View on GitHub (pinned to 59484858a1)

Solutions

  1. Run `yarn install` manually to see detailed output beyond the rejection message.
  2. Resolve yarn.lock conflicts: delete the lockfile and regenerate.
  3. For Yarn Berry, check .yarnrc.yml configuration and plugin setup.
  4. Check Node.js version compatibility with your Yarn version.
  5. Clear Yarn's cache: `yarn cache clean` (Classic) or check `.yarn/cache` (Berry).

Example fix

// before: yarn install fails
// Error: Yarn failed to install modules: Command failed with exit code 1

// after: run manually for details
// $ cd <project-root> && yarn install
// fix the issue shown in yarn's verbose output
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: verify yarn is available and configured
const {execSync} = require('child_process');

function preflightYarn() {
  try {
    let version = execSync('yarn --version', {encoding: 'utf8'}).trim();
    return version;
  } catch {
    throw new Error('yarn is not installed or not on PATH');
  }
}

Try / catch

try {
  await yarnInstaller.install({modules, saveDev, cwd, packagePath, fs});
} catch (e) {
  if (e.message.startsWith('Yarn failed to install modules')) {
    // Extract the inner error message
    let innerError = e.message.replace('Yarn failed to install modules:', '').trim();
    console.error('Yarn error:', innerError);
    // Run yarn manually for full output
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: install() is called on the Yarn class, which spawns `yarn install` as a child process with JSON output parsing. The process exits non-zero, causing promiseFromProcess to reject. The catch block captures the rejection and re-throws with 'Yarn failed to install modules:' prepended.

Common situations: Yarn offline cache miss when using --offline mode. yarn.lock conflicts after a merge. Network issues reaching the registry. Yarn version mismatch (Yarn Classic vs Yarn Berry) with the project's .yarnrc.yml. Node.js version incompatible with the installed Yarn version.

Related errors


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