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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: @babel/parser
fails when loading options programatically
#14082
Comments
Hey @mskelton! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite. |
This never worked. Maybe it didn't throw with your exact config, but it definitely didn't do what you expect.
What you want is to use const { parseSync, loadOptions } = require("@babel/core");
const input = `
console.log('mark')
`;
parseSync(input, loadOptions()) |
Actually, we might throw/log an helpful message when passing |
Okay, so looking back I see that my repro was slightly incorrect. The stylelint bug is happening when importing |
Looking deeper into this, seems like it isn't a Babel issue. Appreciate the help though! |
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Configuration file name
babel.config.js
Configuration
Current and expected behavior
When parsing with the following code:
Babel will fail with the following error:
Environment
System:
Binaries:
npmPackages:
Possible solution
Update
hasPlugin
inpackages/babel-parser/src/plugin-utils.js
to test all types of plugin objects (string, array,ConfigItem
,Plugin
, etc.).Additional context
A recent change to
hasPlugin
in #13982 broke certain programatic usages of the Babel API when loading config from ababel.config.js
file. This does not occur when loading from a.babelrc
file interestingly enough.This is used in the wild as it is the cause of https://github.com/stylelint/postcss-css-in-js/issues/247.
A full working example is available here: https://github.com/mskelton/babel-repro/blob/working/parse.js
The text was updated successfully, but these errors were encountered: