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

Macros don't work with ts-loader. #460

Closed
chrischen opened this issue Feb 20, 2019 · 3 comments
Closed

Macros don't work with ts-loader. #460

chrischen opened this issue Feb 20, 2019 · 3 comments

Comments

@chrischen
Copy link

chrischen commented Feb 20, 2019

Describe the bug
Some Text is empty if no defaults prop is set.
I'm not totally sure if this is a babel-plugin-macros issue or an issue with lingui.

To Reproduce
Use ts-loader in webpack before passing to babel-loader.

Initialize with with no props.

import { Trans } from "@lingui/macro"



export default function App() {
   return <>
      <Trans>Some Text</Trans> // -> Is empty
      <Trans defaults="default text">Some Text</Trans> // -> `default text` shows
   </>;
}

Expected behavior
I Expect Some Text to render in the absence of a translation.

Additional context
Add any other context about the problem here.

  • jsLingui version lingui --version 2.7.4
  • Babel version npm list babel-core 7.3.3
  • Your Babel config (e.g. .babelrc) or framework you use (Create React App, Meteor, etc.)
    { "plugins": [ "@loadable/babel-plugin", "@babel/plugin-syntax-dynamic-import", "react-hot-loader/babel", "emotion", "macros" ] }
    Using an almost fresh instance of ReactQL boilerplate.

Also getting this notice in console.
@lingui/babel-preset-react is probably missing in babel config, but you are using <Trans> component in a way which requires it. Either don't use children in <Trans> component or configure babel to load @lingui/babel-preset-react preset. See tutorial for more info

** UPDATE **
I've confirmed that the macro is not working, as the react element is equivalent to calling from "@lingui/react". I'm not sure why it's not working, but I feel like it should at least give better errors that the macro isn't working.

@chrischen chrischen changed the title Message ID not being shown when no fallback and no translation Macros don't work with ts-loader. Feb 21, 2019
@chrischen
Copy link
Author

I managed to fix it by migrating from ts-loader to babel's support for typescript via @babel/preset-typescript.

@tricoder42
Copy link
Contributor

Hey @chrischen, the macros only work with babel right now. There's an ongoing effort to bring macros to TS as well

Feel free to update the macro docs and send a PR or there's even a dedicated guide to using LinguIJS in Typescript projects.

@chrischen
Copy link
Author

I was using both babel and ts-loader for webpack. I think i can maybe help update the docs with my solution, which was to get rid of ts-loader.

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