multi-progress-bars
multi-progress-bars copied to clipboard
Import as ES Module fails
Right now with version 4.2.0
, importing multi-progress-bars
into a project using ES modules fails like this:
file:///....../node_modules/multi-progress-bars/dist/multi-progress-bars.mjs:1
import { green } from 'chalk';
^^^^^
SyntaxError: Named export 'green' not found. The requested module 'chalk' 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 'chalk';
const { green } = pkg;
It's caused by how the TypeScript transpiler optimize import statements if it compiles to an ES module, and how NodeJS treats CJS imports in said ES modules. The error message suggests a potential solution to the problem, but I'm not sure if the TypeScript transpiler could be configured to achieve these statements.
Related (yet not similar) issues are discussed here and here.
As a side note, the issue doesn't appear if dist/multi-progress-bars.cjs
is imported instead. However, this workaround can't be used with the current multi-progress-bars
release, as it defines an exports
section in its package.json
which masks direct access to the files in the dist/
folder. The workaround would require the exports
to be modified.