js-lingui: Babel throws "Plugin/Preset files are not allowed to export objects, only functions."
lingui 2.0.4, babel 7.0.0-beta.40
> lingui extract --clean
Extracting messages from source files…
/code/App/node_modules/@babel/core/lib/config/config-descriptors.js:158
throw new Error("Plugin/Preset files are not allowed to export objects, only functions.");
^
Error: Plugin/Preset files are not allowed to export objects, only functions.
at createDescriptor (/code/App/node_modules/@babel/core/lib/config/config-descriptors.js:158:11)
at /code/App/node_modules/@babel/core/lib/config/config-descriptors.js:101:12
at Array.map (<anonymous>)
at createDescriptors (/code/App/node_modules/@babel/core/lib/config/config-descriptors.js:100:27)
at createPresetDescriptors (/code/App/node_modules/@babel/core/lib/config/config-descriptors.js:92:10)
at /code/App/node_modules/@babel/core/lib/config/config-descriptors.js:64:19
at presets (/code/App/node_modules/@babel/core/lib/config/config-descriptors.js:54:25)
at mergeChainOpts (/code/App/node_modules/@babel/core/lib/config/config-chain.js:294:68)
at /code/App/node_modules/@babel/core/lib/config/config-chain.js:247:7
at buildRootChain (/code/App/node_modules/@babel/core/lib/config/config-chain.js:83:20)
There’s a closed issue mentioning something like this: https://github.com/lingui/js-lingui/issues/163
The difference is that I actually updated to 2.0.4 from 2.0.0 and got this error (while the author of issue#163 had an opposite situation - he was getting this on 2.0.2 and it was “fixed” and updated to 2.0.4)
Any ideas how to fix that?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 27 (17 by maintainers)
@adamgruber Absolutely. I’m planning releasing new version using Babel 6 with new major version using Babel 7 (even in beta). I’m just fixing some Babel-related issues, so once it’s ready, I’m gonna publish it.
I have the exact same issue
@tricoder42 I did some digging on this and found that the problem does come from mixing plugins from Babel 6 and 7. The reason this happens is that inside the babel extractor, the method,
transformFileSync, is called which attempts to load the user’s.babelrcfile. So, if a user’s.babelrcfile includes any presets/plugins meant for Babel 6 it fails and we get the error message.The
transformFileSyncmethod takes ababelrcoption which, when set tofalse, will skip loading the user’s config. The problem with this is then JSX files are not transformed since Babel doesn’t load the preset for it. Lingui could be updated to include the React preset directly but we would still have issues if users need to transform their code with other presets/plugins.One workaround is to use Babel’s
envfeature to create a separate config for lingui. Example:While this will work, it requires users to create separate blocks for
developmentandproductionsince Babel’s default behavior of mergingenvoptions with non-env options will put us back where we started with mixed presets/plugins.In my opinion the best way forward here is to revert the Babel 7 change and release a new
2.X.Xversion. Then, a3.X.Xversion can be released with Babel 7 added back in since it was a breaking change.An alternative could be to update the
extractcommand to accept some options to let users point to a specific babel config but this forces users to manage multiple configs which is not ideal.We also faced this problem. The breaking change was in
@lingui/cli2.0.2.@lingui/cli2.0.1 still works if you have a Babel 6 version.More specifically, this commit used to make it work: https://github.com/lingui/js-lingui/commit/99f3f5daf640928941e62d05b9f1ac5dfa3ccf7d#diff-17502638c53a6f9c1aad8483bb8b2551
After that commit,
@lingui/clibreaks for anyone who uses Babel 6.@Smolations have you tried v2.0.2? Worked for me
@ktunkiewicz Messages are extracted using babel plugin, so you need full babel config. It might be a problem that we’re mixing babel6 and babel7 plugins. I would suggest extract babel config from webpack one. Similar workaround is needed for create-react-app, neutrino and all other 0config tools which hard-code babel config to webpack one.
I guess we might use a different method to extract messages, but take advantage of Babel AST and write a custom babel plugin was the easiest way to start.
@bs1180 I’ll take a look, thanks for the repo!
I also checked version 2.0.2 and it works fine, no errors, only when I switch to 2.0.4.