{"record":{"id":"483e1bf04a9c71d9","repo":"usebruno/bruno","slug":"could-not-resolve-module-modulename-mainer","errorCode":null,"errorMessage":"Could not resolve module \"${moduleName}\": ${mainError.message}\n\nInstall it with: npm install ${moduleName}","messagePattern":"Could not resolve module \"(.+?)\": (.+?)\n\nInstall it with: npm install (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-js/src/sandbox/node-vm/cjs-loader.js","lineNumber":316,"sourceCode":"      // Not found via walk-up, continue to fallbacks\n    }\n  }\n\n  if (!resolvedPath && collectionPath) {\n    try {\n      const collectionRequire = nodeModule.createRequire(path.join(collectionPath, 'package.json'));\n      resolvedPath = collectionRequire.resolve(moduleName);\n    } catch {\n      // Module not found in collection, continue to fallback\n    }\n  }\n\n  // Fall back to Bruno's bundled node_modules\n  if (!resolvedPath) {\n    try {\n      resolvedPath = require.resolve(moduleName, { paths: module.paths });\n    } catch (mainError) {\n      throw new Error(\n        `Could not resolve module \"${moduleName}\": ${mainError.message}\\n\\n`\n        + `Install it with: npm install ${moduleName}`\n      );\n    }\n  }\n\n  return executeModuleInVmContext({\n    resolvedPath,\n    moduleName,\n    isolatedContext,\n    collectionPath,\n    localModuleCache\n  });\n}\n\n/**\n * Creates the require function handed to a loaded npm module. Resolution is\n * plain Node.js walk-up from the module's own directory — internal relative","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/sandbox/node-vm/cjs-loader.js#L298-L334","documentation":"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.","triggerScenarios":"require('not-installed-pkg') in a Bru script where the package is neither installed in the collection nor bundled into Bruno.","commonSituations":"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.","solutions":["Run `npm install <moduleName>` in the collection root (the directory containing the collection's package.json) and re-run the request.","Check the spelling and casing of the module name against the npm registry exactly (package names are case-sensitive).","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.","Ensure the collection's package.json is at the path Bruno treats as collectionPath and that node_modules lives next to it."],"exampleFix":"# before — module not installed\nrequire('lodash');  // -> Could not resolve module \"lodash\"\n\n# after\nnpm install lodash --save\n# then re-run the request","handlingStrategy":"validation","validationCode":"function canResolve(name) {\n  try { require.resolve(name, { paths: require('module').paths }); return true; }\n  catch { return false; }\n}\nif (!canResolve('lodash')) throw new Error('run: npm install lodash');","typeGuard":null,"tryCatchPattern":"try {\n  const lib = require('some-pkg');\n} catch (err) {\n  if (/Could not resolve module/.test(err.message)) {\n    // prompt install or switch to a bundled module\n  }\n  throw err;\n}","preventionTips":["Run `npm install` in the collection root after cloning or pulling changes.","Double-check scoped package names and casing.","Commit the collection's package.json so teammates install the same deps."],"tags":["bruno-js","node-vm","sandbox","module-resolution","npm"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}