Skip to content

TypeError: appenderModule.configure is not a function #1411

@Wrightlt

Description

@Wrightlt

Node.js: v16.16.0 Nuxt: 2.15.8 log4js: 6.9.1

Hi.

I am triying to use log4js in Nuxt,it is work, but it's throwing an error: TypeError: appenderModule.configure is not a function.

this is my log4js.js:

// const log4js = require("log4js");
// import log4js from 'log4js';
import * as log4js from "log4js";

const config = {
    appenders: {
        info: {
            info: { type: "file", filename: "logs/info.log" },
        },
    },
    categories: {
        default: { appenders: ['debug', 'info', 'error'], level: 'info' },
    },
};
log4js.configure(config);

export default log4js;

I tried three different approaches:
Approach 1: const log4js = require("log4js");
Approach 2: import log4js from 'log4js';
Approach 3: import * as log4js from "log4js";
But all of them resulted in the above-mentioned error.

usage:

<template>
    <div>ttt6666888</div>
</template>

<script>
import log4js from './log4js';


export default {
    name: "IndexPage",
    asyncData() {

      const logger = log4js.getLogger('info');
      logger.info('info~~~');

        return {
          test: 111
        }
    }
}
</script>

error is:

TypeError: appenderModule.configure is not a function
    at eval (index.js:117:29)
    at Object.onlyOnMaster (clusteringBrowser.js:13:50)
    at createAppender (index.js:112:21)
    at getAppender (index.js:68:20)
    at eval (index.js:147:7)
    at Array.forEach (<anonymous>)
    at setup (index.js:139:33)
    at eval (configuration.js:51:35)
    at Array.forEach (<anonymous>)
    at Object.configure (configuration.js:51:13)

But when I directly use log4js in a component, it works and doesn't throw an error.
my component:

<template>
    <div>test11</div>
</template>

<script>
const log4js = require("log4js")

export default {
    name: "IndexPage",
    asyncData() {
        log4js.configure({
            appenders: {
                out: { type: "stdout" },
                app: { type: "file", filename: "logs/app.log" }
            },
            categories: {
                default: { appenders: ["out", "app"], level: "debug" }
            }
        })
        const logger = log4js.getLogger("cheese")

        logger.info("Cheese is Comté.")
        logger.error("Cheese is too ripe!")
    }
}
</script>
Do you have any solutions for this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy