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

configPath is not set when calling getConfig in babel-plugin-extract-messages #1137

Closed
mattdaly opened this issue Sep 17, 2021 · 2 comments · Fixed by #1140
Closed

configPath is not set when calling getConfig in babel-plugin-extract-messages #1137

mattdaly opened this issue Sep 17, 2021 · 2 comments · Fixed by #1140

Comments

@mattdaly
Copy link

mattdaly commented Sep 17, 2021

Describe the bug
When using a lingui config that is not located at the root, extraction fails because babel cannot find the config. The result is a Cannot process file <filename>: Cannot find module <config> error for each file being processed, and no translations being extracted.

To Reproduce
Place a lingui config in a nested directory and pass its path to the --config argument when calling extract - no translations are extracted and the error noted above is received for each file being parsed.

Expected behavior
That custom config paths are passed to the configPath property for all calls to getConfig, specifically in this case in babel-plugin-extract-messages.

Adding a default lingui config at the root that imports and re-exports the nested config is the only solution without changes to lingui itself.

Passing a configPath to getConfig in babel-plugin-extract-messages fixes the issue. I have tested and verified this by setting configPath: process.env.LINGUI_CONFIG (and obviously setting the value of that env var) - I did not look at how to pass the initial program.config all the way down to the extractor.

getConfig({ cwd: file.opts.filename, skipValidation: true })

Additional context
We have an internal custom build tool that wraps webpack and configures module federation for use across our micro frontends. Part of that build tool is a wrapper around lingui that defines a default lingui config appropriate for our chosen micro frontend structure and provides a cli to extract translations as part of our ci process. It is very similar to create-react-app, with module federation, lingui and some others.

This means that in our micro frontends themselves, the lingui config is located within the node_modules directory, and not at the root. Without defining a lingui config at the root of each micro frontend that imports and re-exports the lingui config from our build tool, no translations are extracted.

@mattdaly mattdaly changed the title Bug: configPath is not set when calling getConfig in babel-plugin-extract-messages configPath is not set when calling getConfig in babel-plugin-extract-messages Sep 17, 2021
@semoal
Copy link
Contributor

semoal commented Sep 17, 2021

Will look into it asap :)

@semoal
Copy link
Contributor

semoal commented Sep 27, 2021

Will look in to this tonight, for releasing a new version this week :)

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

Successfully merging a pull request may close this issue.

2 participants