usebruno/bruno · error · Error

Could not resolve module "${moduleName}": ${mainError.messag

Error message

Could not resolve module "${moduleName}": ${mainError.message}

Install it with: npm install ${moduleName}

What it means

Thrown by loadNpmModule in Bruno's node-vm CJS loader after every resolution strategy has failed: the module was not found via walk-up from the calling module's node_modules, not from the collection's node_modules, and not from Bruno's bundled node_modules fallback. The error message appends an `npm install <name>` hint.

Source

Thrown at packages/bruno-js/src/sandbox/node-vm/cjs-loader.js:316

      // Not found via walk-up, continue to fallbacks
    }
  }

  if (!resolvedPath && collectionPath) {
    try {
      const collectionRequire = nodeModule.createRequire(path.join(collectionPath, 'package.json'));
      resolvedPath = collectionRequire.resolve(moduleName);
    } catch {
      // Module not found in collection, continue to fallback
    }
  }

  // Fall back to Bruno's bundled node_modules
  if (!resolvedPath) {
    try {
      resolvedPath = require.resolve(moduleName, { paths: module.paths });
    } catch (mainError) {
      throw new Error(
        `Could not resolve module "${moduleName}": ${mainError.message}\n\n`
        + `Install it with: npm install ${moduleName}`
      );
    }
  }

  return executeModuleInVmContext({
    resolvedPath,
    moduleName,
    isolatedContext,
    collectionPath,
    localModuleCache
  });
}

/**
 * Creates the require function handed to a loaded npm module. Resolution is
 * plain Node.js walk-up from the module's own directory — internal relative

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Run `npm install <moduleName>` in the collection root (the directory containing the collection's package.json) and re-run the request.
  2. Check the spelling and casing of the module name against the npm registry exactly (package names are case-sensitive).
  3. If the package is bundled by Bruno (chai, ajv, axios, etc.), confirm it is on the supported list and not shadowed by a broken local install.
  4. Ensure the collection's package.json is at the path Bruno treats as collectionPath and that node_modules lives next to it.

Example fix

# before — module not installed
require('lodash');  // -> Could not resolve module "lodash"

# after
npm install lodash --save
# then re-run the request
Defensive patterns

Strategy: validation

Validate before calling

function canResolve(name) {
  try { require.resolve(name, { paths: require('module').paths }); return true; }
  catch { return false; }
}
if (!canResolve('lodash')) throw new Error('run: npm install lodash');

Try / catch

try {
  const lib = require('some-pkg');
} catch (err) {
  if (/Could not resolve module/.test(err.message)) {
    // prompt install or switch to a bundled module
  }
  throw err;
}

Prevention

When it happens

Trigger: require('not-installed-pkg') in a Bru script where the package is neither installed in the collection nor bundled into Bruno.

Common situations: Forgot to run `npm install` in the collection directory; typo or wrong casing in the package name; scoped package with the scope omitted; package was installed but in a different workspace/monorepo root than the one Bruno resolves from; the package exists only as a devDependency that did not get installed.

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/483e1bf04a9c71d9. Report an issue: GitHub.