Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

File opts.messagesDir not created because descriptors.length == 0 #92

Closed
googol7 opened this issue Jan 13, 2017 · 16 comments · Fixed by #96
Closed

File opts.messagesDir not created because descriptors.length == 0 #92

googol7 opened this issue Jan 13, 2017 · 16 comments · Fixed by #96

Comments

@googol7
Copy link

googol7 commented Jan 13, 2017

The directory defined in opts.messagesDir is not being created with version > 2.1.4

commit 48b7d47 is the first one that doesn’t work anymore.

created a repo here for you to test:
https://github.com/googol7/test-babel-plugin-react-intl

babel-plugin-react-intl@2.1.4 works
babel-plugin-react-intl@2.2.0 doesn’t work anymore
babel-plugin-react-intl@2.3.0 doesn’t work either

please try these commands:

npm run translate

or

./translate.sh

I suppose it’s connected to these issues where the command is run twice and the second time descriptors.length == 0:
#28
#25

Is there something wrong in my configuration or is there a bug with versions > 2.1.4?

@ericf
Copy link
Collaborator

ericf commented Jan 13, 2017

There hasn't been any changes to the code that actually writes out of the .json files between 2.1.4 and latest.

@googol7
Copy link
Author

googol7 commented Jan 13, 2017

The test repo I made is very reduced and set up according to the setup instructions.

Please try this to reproduce the problem:

git clone git@github.com:googol7/test-babel-plugin-react-intl.git
cd test-babel-plugin-react-intl/
yarn install
npm run translate

an error occurs because the directory extracted-messages was not created.

then downgrade:

yarn add babel-plugin-react-intl@2.1.4
npm run translate

voilà - it works - the directory "extracted-messages" was created.

after upgrading with

yarn add babel-plugin-react-intl@2.3.0
npm run translate

the error occurs again because 2.3.0 doesn't create the directory "extracted-messages".

@googol7
Copy link
Author

googol7 commented Jan 18, 2017

@ericf could you please have a quick look at the repo https://github.com/googol7/test-babel-plugin-react-intl what’s wrong with my setup?

@chemoish
Copy link

I am having a similar issue with babel#6.9.1 and babel-plugin-react-intl#2.3.0 where no messages are being generated.

I will roll back and see when this issue started.

@chemoish
Copy link

chemoish commented Jan 23, 2017

@ericf I can confirm that as of 2.2.0, messages are no longer generated. Messages now are []—like @googol7 says, they work fine in 2.1.4.

Specifically, babel --plugins react-intl script.js no longer works.


Additionally, I have found a work around.

BABEL_ENV=i18n babel src > /dev/null

// .babelrc
{
  "env": {
    "i18n": {
      "plugins": [
        ["react-intl", {
          "enforceDescriptions": true,
          "messagesDir": "./src/i18n/messages"
        }]
      ]
    }
  }
}

(obviously environment isn't needed, but running babel on entire directory without passing in a --plugins argument seems to generate messages correctly)

@ericf
Copy link
Collaborator

ericf commented Jan 24, 2017

I haven't had a chance to look at this yet. If you guys see anything in the commits between the versions that work and don't work let me know, or send a PR if you find a fix.

@ericf
Copy link
Collaborator

ericf commented Jan 25, 2017

I see the README docs encourage someone to end up adding the plugin twice, once via .babelrc and again via the command line --plugins react-intl. I should update the docs to remove the command line usage since that's never going to yield what someone wants and cause the plugin to be added multiple times.

If you guys remove --plugins react-intl from your babel command line the problem should be resolved. And I'll look to improve things in the plugin to recognize this state and try to do something better.

@googol7
Copy link
Author

googol7 commented Jan 25, 2017

@ericf thanks!

@ericf
Copy link
Collaborator

ericf commented Jan 25, 2017

I was able to reproduce and --plugins react-intl CLI option causes the issue because it adds an instance of the babel plugin without any config options set. When the second instance of the plugin runs that's defined and configured in .babelrc it becomes a noop. I can produce a warning when multiple instances of the babel plugin is detected, I'll try to see if I can warn about --plugins usage since it's most likely not what people want since you can't configure it to do anything useful.

@ericf
Copy link
Collaborator

ericf commented Jan 25, 2017

Alright I figured out a fix for this issue without warning. It Just Works™

ericf added a commit that referenced this issue Jan 25, 2017
This fixes issues without writing the extracted messages out to the
filesystem when multiple instances of the plugin are being applied.

This also removes the CLI usage docs which say to use `--plugins`
option because this is not useful for this plugin since it needs to
be configured via `.babelrc` or use via Babel's API.

Fixes #92
@ericf ericf closed this as completed in #96 Jan 25, 2017
ericf added a commit that referenced this issue Jan 25, 2017
This fixes issues without writing the extracted messages out to the
filesystem when multiple instances of the plugin are being applied.

This also removes the CLI usage docs which say to use `--plugins`
option because this is not useful for this plugin since it needs to
be configured via `.babelrc` or use via Babel's API.

Fixes #92
@ericf
Copy link
Collaborator

ericf commented Jan 25, 2017

@googol7 @chemoish this should be fix in v2.3.1, give it a try and let me know!

@chemoish
Copy link

@ericf not sure what changed, but your comment above makes sense.

I tried to use --plugins react-intl and get no warnings or files generated.

When I just leverage .babelrc, using the code I listed above, it works the same between 2.3.0 and 2.3.1—files are generated.

Either way I am updating my code to match the snippet above since what you said makes sense.

@ericf
Copy link
Collaborator

ericf commented Jan 26, 2017

--plugins react-intl when used on its own won't yield anything useful.

If you configured the plugin with .babelrc and also included it via --plugins — which causes it to be included twice — it'll now output the messages that were extracted from this first instance of the plugin to the file system.

Essentially what I did was allow the plugin to work as expect, even when it's being included more that one time. I was able to do this without having to add warnings. There's also no way for me to detect in the plugin whether it was added via .babelrc or --plugins.

@chemoish
Copy link

chemoish commented Jan 26, 2017

Right i was using --plugin react-intl WITH .babelrc (with no avail)—but no worries, i will just use .babelrc on its own.

Thanks for the help!

@ericf
Copy link
Collaborator

ericf commented Jan 26, 2017

Not sure why. I tested it this way and saw the issue, then with my changes the issue was fixed.

@googol7
Copy link
Author

googol7 commented Jan 26, 2017

@ericf your fix in v2.3.1 works. thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants