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

In development when using ESM version messages are not "compiled" #1063

Closed
MartijnHols opened this issue May 14, 2021 · 2 comments
Closed

In development when using ESM version messages are not "compiled" #1063

MartijnHols opened this issue May 14, 2021 · 2 comments

Comments

@MartijnHols
Copy link

MartijnHols commented May 14, 2021

Describe the bug
In development, before extracting new messages, translations are not being compiled meaning variables are not being replaced with their values.

To Reproduce
Set up a project that uses the ESM imports in development mode.

import { Trans } from "@lingui/react"

export default function App() {
   const somethingElse = 'replaced'
   return <Trans id="my.id">This should be {somethingElse}!</Trans>
}

This will render This should be {somethingElse}! when using the development ESM version of the library @lingui/core (dev.esm.js). This becomes This should be replaced! If you switch to the CJS version (core.development.js or dev.development.js).

Expected behavior
The ESM versions works the same as the CJS version.

Additional context
The issue seems to be that these lines:

if (process.env.NODE_ENV !== "production") {
translation = isString(translation)
? icu.compile(translation)
: translation
}

Are missing from the generated ESM file:

     {
        key: '_',
        value: function (e) {
          var t =
              arguments.length > 1 && void 0 !== arguments[1]
                ? arguments[1]
                : {},
            r =
              arguments.length > 2 && void 0 !== arguments[2]
                ? arguments[2]
                : {},
            n = r.message,
            a = r.formats
          i(e) || ((t = e.values || t), (n = e.message), (e = e.id))
          var o = this.messages[e] || n || e,
            l = this._missing
          return l && !this.messages[e]
            ? s(l)
              ? l(this.locale, e)
              : l
            : (this.messages[e] ||
                this.emit('missing', { id: e, locale: this._locale }),
              i(o) && /\\u[a-fA-F0-9]{4}/g.test(o)
                ? JSON.parse('"'.concat(o, '"'))
                : i(o)
                ? o
                : d(o, this.locale, this.locales, this.localeData)(t, a))
        },
      },

I pressume this is because dev.esm.js is generated using a production value for the NODE_ENV, rather than development. Looking at

case ESM_PROD:
there doesn't seem to be a development ESM build.

  • jsLingui version 3.8

ps. the fact that the ESM files are uglified makes debugging harder, and makes the components have unreadable component names in the React Developer Tools and stack traces.

@semoal
Copy link
Contributor

semoal commented May 14, 2021

#1059
It's already fixed, on the next tuesday will be released

@semoal
Copy link
Contributor

semoal commented May 18, 2021

Released 3.9.0 give it a try when you can, but i'm pretty sure that will fixed :)

@semoal semoal closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants