formatjs / formatjs

The monorepo home to all of the FormatJS related libraries, most notably react-intl.

Home Page:https://formatjs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@formatjs/cli-lib is not an ESM module

danilofuchs opened this issue · comments

Which package?

@formatjs/cli-lib

Describe the bug

When trying to import the library from a pure ESM project:

import { extractAndWrite } from "@formatjs/cli-lib";
         ^^^^^^^^^^^^^^^
SyntaxError: Named export 'extractAndWrite' not found. The requested module '@formatjs/cli-lib' 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 '@formatjs/cli-lib';
const { extractAndWrite } = pkg;

To Reproduce

Create a simple Node project with type: module

// index.js
import { extractAndWrite } from "@formatjs/cli-lib";

Expected behavior

Imports just work, no need for a workaround

Version

Node.js 20.11.0