unjs / consola

🐨 Elegant Console Logger for Node.js and Browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

withScope is not a function : withScope chaining

linqFR opened this issue · comments

I m quite confused : sometimes it works and other it does not ! i guess it depends on context (import or require)

import consola from 'consola'
const logger = consola.withScope('scope') // is Ok

const newlogger = console.withScope('other') // is not Ok (withScope is not a function)

But it worked in some other situations i coded

I guess it comes from /node-modules/consola/dist/console.cjs.js
I have the feeling prototypes are missing in the new consola created by withScope/withDefaults: logger is just an object and no longer a Consola.

var Consola =
/*#__PURE__*/
function () {
  function Consola() {
    var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

    _classCallCheck(this, Consola);

    this.reporters = options.reporters || [];
    this.types = Object.assign({}, types, options.types);
    this.level = options.level != null ? options.level : 3;
    Object.assign(this, this.withDefaults());
  }

  _createClass(Consola, [{
    key: "withDefaults",
    value: function withDefaults(defaults) {
      var logger = {};

      for (var type in this.types) {
        logger[type] = this._createLogFn(Object.assign({
          type: type
        }, this.types[type], defaults));
      }

      return logger;
    }
  }

const newlogger = console.withScope('other') // is not Ok (withScope is not a function)
you're using console instead of consola