Js-lingui: CLI extract throws error when using macros

Created on 15 Sep 2018  ·  8Comments  ·  Source: lingui/js-lingui

Describe the bug
I am getting an error when trying to extract messages. It is doing for all my files with translation after I have upgraded to the macros.

To Reproduce

// .babelrc
{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-flow"
  ],
  "plugins": [
    "universal-import",
    "react-hot-loader/babel",
    "babel-plugin-macros",
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-export-default-from",
    "@babel/plugin-proposal-optional-chaining"
  ]
}
// extract command
✔ /Volumes/sites/findoc/src/components/booking/BookingCalendarMultiSpec/DayAvailabilityMultiSpec/index.js
✔ /Volumes/sites/findoc/src/components/booking/BookingCalendarMultiSpec/index.js
⠋ /Volumes/sites/findoc/src/components/booking/bookingSectionTitle/BookingSectionTitle.jsx/Volumes/sites/findoc/node_modules/babel-plugin-macros/dist/index.js:165
    byName[importedName] = path.scope.getBinding(localName).referencePaths;
                                                           ^

TypeError: Cannot read property 'referencePaths' of undefined
    at /Volumes/sites/findoc/node_modules/babel-plugin-macros/dist/index.js:165:60
    at Array.reduce (<anonymous>)
    at applyMacros (/Volumes/sites/findoc/node_modules/babel-plugin-macros/dist/index.js:161:44)
    at /Volumes/sites/findoc/node_modules/babel-plugin-macros/dist/index.js:132:24
    at Array.forEach (<anonymous>)
    at PluginPass.VariableDeclaration (/Volumes/sites/findoc/node_modules/babel-plugin-macros/dist/index.js:122:51)
    at newFn (/Volumes/sites/findoc/node_modules/@babel/traverse/lib/visitors.js:243:21)
    at NodePath._call (/Volumes/sites/findoc/node_modules/@babel/traverse/lib/path/context.js:65:18)
    at NodePath.call (/Volumes/sites/findoc/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Volumes/sites/findoc/node_modules/@babel/traverse/lib/path/context.js:100:12)



md5-7c03d26c176f88995870f8e7d7011cea



import React from 'react';
import { Trans } from '@lingui/macro';

const BookingSectionTitle = () => (
  <div className="is-size-4 has-text-white has-text-weight-semibold">
    <Trans>Book an appointment online</Trans>
);

export default BookingSectionTitle;

Additional context

  • jsLingui version: 2.7.0
  • Babel version:
    babel-core: 7.0.0-bridge.0
    @babel/core: 7.0.1
🐞bug 📦 cli

Most helpful comment

It's a bug in babel-plugin-macros https://github.com/kentcdodds/babel-plugin-macros/pull/80

Although I still don't understand why it works in all examples... I was able to figure out it's caused by @babel/env preset, other plugins doesn't affect it at all.

All 8 comments

Hey @MartinCerny-awin,
I tried your setup in webpack-react example, but everything works fine. So I published a minimum example. Could you please clone it and try to reproduce the bug in that repo?

@tricoder42 Just a note, but in repo, you have "babel-core": "^7.0.0-0", but @MartinCerny-awin said he is using the bridge there. I don't know if there is a relevance, but it could be...

babel-core 7.0.0-0 is the bridge. babel-core officially ends with version 6.

On 15 Sep 2018, at 14:03, Daniel K. notifications@github.com wrote:

@tricoder42 Just a not, but in repo, you have "babel-core": "^7.0.0-0", but @MartinCerny-awin said he is using the bridge there. I don't know if there is a relevance, but it could be...


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

It's a bug in babel-plugin-macros https://github.com/kentcdodds/babel-plugin-macros/pull/80

Although I still don't understand why it works in all examples... I was able to figure out it's caused by @babel/env preset, other plugins doesn't affect it at all.

[email protected] has just been released. Please update and let me know if it solves the problem 👍

Actually, I've just test it in https://github.com/tricoder42/lingui-issue-328 and it works! Let me know if you still encounter error.

It works perfectly!

Was this page helpful?
0 / 5 - 0 ratings