formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

intl-messageformat-parser: Unable to import with latest node.js and ESM enabled. #557

Closed joeyhub closed 4 years ago

joeyhub commented 4 years ago

I'm not able to import intl-messageformat-parser 4 in node.js 13, using ESM (mjs and "type": "module").

import {parse} from 'intl-messageformat-parser'; ^^^^^ SyntaxError: The requested module 'intl-messageformat-parser' does not provide an export named 'parse'

longlho commented 4 years ago

we're not supporting ESM ATM but PR's welcome :)

joeyhub commented 4 years ago

Does this need to be require instead?

https://www.npmjs.com/package/intl-messageformat-parser

longlho commented 4 years ago

I believe so. We're waiting until all the bundlers and friends support ESM properly

joeyhub commented 4 years ago

This works:

import MessageFormatParser from 'intl-messageformat-parser/dist/index.js';

It's a standard workaround but I'm a bit confused because even that wasn't working before. I updated node and the NPM packages so I suspect a bug somewhere stopped that from working before.

Other wise with ESM depending what you do to get it to work without falling back to CJS will either break in node or rollup.

longlho commented 4 years ago

We don't set the necessary meta fields in package.json for Node to recognize it as ESM because that confuses the other bundlers, which is prob why you need to import from a specific path. Just a guess...