Since my project has enabled "type": "module" in package.json, an error was thrown when I imported it.
If I remove "type": "module" and use the CJS module, all modules in my project will need to be rewritten. Is there a good solution? thank
The following is the error message:
import { configure, getLogger } from "log4js";
^^^^^^^^^
SyntaxError: Named export 'configure' not found. The requested module 'log4js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'log4js';
const { configure, getLogger } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:105:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:151:5)
at async Loader.import (node:internal/modules/esm/loader:166:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
Since my project has enabled
"type": "module"inpackage.json, an error was thrown when I imported it.If I remove
"type": "module"and use the CJS module, all modules in my project will need to be rewritten. Is there a good solution? thankThe following is the error message: