You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
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 togetConfig
, specifically in this case inbabel-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
togetConfig
in babel-plugin-extract-messages fixes the issue. I have tested and verified this by settingconfigPath: process.env.LINGUI_CONFIG
(and obviously setting the value of that env var) - I did not look at how to pass the initialprogram.config
all the way down to the extractor.js-lingui/packages/babel-plugin-extract-messages/src/index.ts
Line 255 in 8590c1a
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.The text was updated successfully, but these errors were encountered: