Js-lingui: plurals$$1 is not a function

Created on 16 Jan 2019  路  13Comments  路  Source: lingui/js-lingui

I've just noticed an error that was previously working correctly in my setup. I'm having a hard time tracking down what is causing it.

TypeError: plurals$$1 is not a function at Object.plural (/node_modules/@lingui/core/cjs/core.development.js:101:43)

This only seems to happen when using the macro

<Plural value={1} one="There is # message" other="There are # messages" />

My app is based off of Next.js

"@lingui/react": "2.7.2",
"@lingui/macro": "2.7.2",
"babel-core": "7.0.0-bridge.0",

babelrc:

{ "plugins": ["babel-plugin-idx", "macros"], "env": { "development": { "presets": ["next/babel"], "plugins": [ [ "babel-plugin-styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] ] }, "production": { "presets": ["next/babel"], "plugins": [ [ "babel-plugin-styled-components", { "ssr": true, "displayName": false, "preprocess": false } ] ] }, "test": { "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]], "plugins": [ [ "babel-plugin-styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] ] } } }
plurals$$1 is undefined in @lingui/core/cjs/core.development.js where, when I have tested the same setup using Create React App it is a function called 'en', some I'm thinking I may be missing something??

Most helpful comment

Had the same error but got rid of it when I setup the i18n with a language, i.e. :

const i18n = setupI18n({
  language: 'fi',
});

All 13 comments

After a bit more investigating it looks like this is caused by setting a new instance of i18n so we could use translations outside of react as suggested in docs:

import { setupI18n } from '@lingui/core';

export const i18n = setupI18n();

<I18nProvider language="en-US" catalogs={catalogs} i18n={i18n}>

Removing the i18n prop gets rid of the the error

I am getting the same error and it seems like a bug to me:

import { setupI18n } from "@lingui/core";
import { t, plural } from "@lingui/macro";

const i18n = setupI18n();

export default () => {
  const name = "Foo";
  const count = 3;

  // The first two calls work:

  console.log(
    "t macro (works)",
    i18n._(t("templates.tag.frontmatter.title")`Articles about ${name}`),
  );

  console.log(
    "plural macro (works)",
    plural({
      one: "# post",
      other: "# posts",
      value: count,
    }),
  );

  // These two don't:

  console.log(
    "i18n.plural (doesn't work)",
    i18n.plural({
      one: "# post",
      other: "# posts",
      value: count,
    }),
  );

  console.log(
    "plural macro + i18n._ (doesn't work)",
    i18n._(
      plural({
        one: "# post",
        other: "# posts",
        value: count,
      }),
    ),
  );

  return (<span>test</span>);
}

Anything new here? I am having the same issue

So I was using i18n.plural() which worked in development but didn't work when deployed in a production environment. I get l.c.plural is not a function. I'm about to try a deploy where I switch to using i18n._(plural()) which also worked in local development but no idea if it will work deployed

So i18n._(plural()) worked using the plural macro. This is definitely a bug, since it works in development mode. But it would be just as good to update the docs on this page to reflect correct usage: https://lingui.js.org/guides/plurals.html

Had the same error but got rid of it when I setup the i18n with a language, i.e. :

const i18n = setupI18n({
  language: 'fi',
});

This issue has been opened for 8 months ago. I encounter the same error now. Any update on that?

@blasterbug which version of lingui are you using and how are you using it? I just ran into this issue while implementing v3 in my own project, and it was because I wasn't manually including pluralizations, which is expected by the library.

@tstirrat15 latest version, with React and the standard tools (wepback, Babel)

latest version

Meaning v3 or v2.9?

@tstirrat15 2.9.1

Someone opened a similar issue in remirror which is using lingui. It turns out the issue was that their webpack build process was excluding .mjs files which the underlying plurals library uses for esm builds.

Perhaps something similar is happening here. Check that .mjs files are not being excluded by the build.

Closing in favor or #798

Was this page helpful?
0 / 5 - 0 ratings