Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use on Node.js ESM #152

Open
sonnyp opened this issue Mar 20, 2021 · 3 comments
Open

Cannot use on Node.js ESM #152

sonnyp opened this issue Mar 20, 2021 · 3 comments

Comments

@sonnyp
Copy link

sonnyp commented Mar 20, 2021

Using "native" Node.js ESM doesn't work with ttag because the ttag module only has a default export there and no named exports.

import ttag from 'ttag';
const {t, useLocale, addLocale, ngettext, msgid} = ttag;
sonny@machop ~/foo > npx ttag update locales/es.po server/
⠙ app/src/App.jsError: /foo/bar.js: You should use ttag imports in form: "import { t } from 'ttag'"

If I try to use named imports with ttag on Node.js ESM I get the following error:

import ttag, {t} from 'ttag';
              ^
SyntaxError: Named export 't' not found. The requested module 'ttag' 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 'ttag';
const {t} = pkg;
@AlexMost
Copy link
Member

Hi @sonnyp, thanks for the feedback!
I think ESM module support is a must-have feature. Need to think about how we can add this support, one thing that we need to keep in mind is that commonjs version must not be broken. Maybe you have some good examples of packages that have esm support already?

@sonnyp
Copy link
Author

sonnyp commented Apr 1, 2021

Take your pick https://github.com/talentlessguy/awesome-node-esm :)

@Zurdge
Copy link

Zurdge commented May 2, 2024

👍 for this.
I'm using Remix and it's throwing the following error

[vite] Named export 't' not found. The requested module 'ttag' 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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants