bettercap/bettercap · error

argument is not a function. Are you looking for `mapTo()`?

Error message

argument is not a function. Are you looking for `mapTo()`?

What it means

The map() operator validates that its projector is a function, throwing this TypeError with a hint pointing at mapTo(). It exists because a common mistake is passing a constant value to map() expecting a transformation to that constant.

Source

Thrown at modules/ui/ui/vendor.js:101948

/*!***********************************************************!*\
  !*** ./node_modules/rxjs/_esm5/internal/operators/map.js ***!
  \***********************************************************/
/*! exports provided: map, MapOperator */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "map", function() { return map; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MapOperator", function() { return MapOperator; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.js");
/* harmony import */ var _Subscriber__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Subscriber */ "./node_modules/rxjs/_esm5/internal/Subscriber.js");
/** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */


function map(project, thisArg) {
    return function mapOperation(source) {
        if (typeof project !== 'function') {
            throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
        }
        return source.lift(new MapOperator(project, thisArg));
    };
}
var MapOperator = /*@__PURE__*/ (function () {
    function MapOperator(project, thisArg) {
        this.project = project;
        this.thisArg = thisArg;
    }
    MapOperator.prototype.call = function (subscriber, source) {
        return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
    };
    return MapOperator;
}());

var MapSubscriber = /*@__PURE__*/ (function (_super) {
    tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"](MapSubscriber, _super);
    function MapSubscriber(destination, project, thisArg) {

View on GitHub (pinned to 8eca2820f3)

Solutions

  1. Wrap constants with mapTo: source$.pipe(mapTo(42)) or map(() => 42)
  2. Provide a real projector function: map(x => x.name)
  3. Check the value passed to map with typeof before piping
  4. If you meant to transform each value, keep the arrow function inside map()

Example fix

// before
 clicks$.pipe(map('clicked'));
// after
 clicks$.pipe(mapTo('clicked')); // or map(() => 'clicked')
Defensive patterns

Strategy: validation

Validate before calling

if (typeof project !== 'function') throw new TypeError('map() requires a projector function; use mapTo() for constants');

Type guard

function isProjector<T, R>(f: unknown): f is (value: T, index: number) => R { return typeof f === 'function'; }

Try / catch

try { src$.pipe(map(p)).subscribe(h); } catch (e) { if (e.message.includes('mapTo()')) { console.error('map() got a non-function; use mapTo for constants'); } else throw e; }

Prevention

When it happens

Trigger: source$.pipe(map(42)), map(someValue) where someValue is data instead of a function, or map(obj.prop) evaluating to a non-function at pipe time.

Common situations: Confusing map with mapTo when projecting to constants; passing an already-computed value from an expression; refactors where a projector function was replaced by its result; mixing Array.prototype.map semantics with RxJS.

Related errors


AI-assisted analysis of bettercap/bettercap@8eca2820f3 (2026-09-02). Data as JSON: /api/errors/d606074f86e8488a. Report an issue: GitHub.