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

Error when aliasing Trans from '@lingui/react' in presence of macro Trans from '@lingui/macro' #1844

Closed
1 of 3 tasks
kzuraniewski opened this issue Feb 2, 2024 · 2 comments
Assignees

Comments

@kzuraniewski
Copy link

kzuraniewski commented Feb 2, 2024

Describe the bug

Aliasing Trans import from '@lingui/react' when '@lingui/macro' is present produces the following error:

Uncaught ReferenceError: Trans is not defined

To Reproduce

Let's assume there is a component translating both direct text and some outside data. When aliasing runtime Trans the error is produced:

import { Trans } from '@lingui/macro';
import { Trans as TransRuntime } from '@lingui/react'; // aliasing here so the names don't collide

const data = [msg`Foo`, msg`Bar`];

export default function App() {
   return (
      <div>
         <Trans>Direct text</Trans> // <- Uncaught ReferenceError: Trans is not defined
         {data.map(el => <TransRuntime id={el.id} />)}
      </div>
   );
}

From what I've tried, it happens only when runtime Trans is aliased:

import { Trans as TransMacro } from '@lingui/macro'; // aliased macro Trans instead, error is gone
import { Trans } from '@lingui/react';
// aliasing both, error is thrown by TransMacro
import { Trans as TransMacro } from '@lingui/macro'
import { Trans as TransRuntime } from '@lingui/react';

Although there is a workaround, no explicit error is shown when we incorrectly alias the components, making it hard to fix. I think it should be possible to name both imports freely.

Additional context

  • jsLingui version: 4.7.0
  • Babel version: 7.23.9
  • Macro support:
  • I'm using SWC with @lingui/swc-plugin
  • I'm using Babel with babel-macro-plugin
  • I'm not using macro
  • Using Vite with babel, config: { plugins: ['macros'] }
@timofei-iatsenko
Copy link
Collaborator

Interesting, i will take a look.

@timofei-iatsenko
Copy link
Collaborator

Should be fixed for babel macro with #1867

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

2 participants