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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

.babelrc format file will cause ts error, but babel.config.js won't #483

Open
iamyoki opened this issue Jul 19, 2022 · 3 comments
Open

.babelrc format file will cause ts error, but babel.config.js won't #483

iamyoki opened this issue Jul 19, 2022 · 3 comments

Comments

@iamyoki
Copy link

iamyoki commented Jul 19, 2022

.babelrc format file will cause ts error, but babel.config.js won't

Error Cause

.babelrc

{
  "presets": [
    ["@babel/preset-env", {"loose": true}],
    "@babel/preset-typescript"
  ]
}

error

馃巵 error /Users/yoki/Desktop/try-preconstruct-monorepo/packages/b/src/helpers.ts: Support for the experimental syntax 'flow' isn't currently enabled (1:8):
馃巵 error
馃巵 error > 1 | export interface Options {
馃巵 error     |        ^
馃巵 error   2 |   name: string
馃巵 error   3 | }
馃巵 error   4 |
馃巵 error
馃巵 error Add @babel/preset-flow (https://git.io/JfeDn) to the 'presets' section of your Babel config to enable transformation.
馃巵 error If you want to leave it as-is, add @babel/plugin-syntax-flow (https://git.io/vb4yb) to the 'plugins' section to enable parsing.
馃巵 info If you want to learn more about the above error, check https://preconstruct.tools/errors
馃巵 info If the error is not there and you want to learn more about it, open an issue at https://github.com/preconstruct/preconstruct/issues/new

If change .babelrc file into babel.config.js

/** @type {babel.ConfigFunction} */
module.exports = (api) => {
  api.cache(true);

  return {
    presets: [
      ['@babel/preset-env', {'loose': true}],
      '@babel/preset-typescript',
    ],
  };
};

Success

馃巵 info building bundles!
馃巵 success built bundles!
@emmatown
Copy link
Member

It's expected that this doesn't work based on how Babel resolves configs. If you want to write a JSON config, you can use babel.config.json.

@iamyoki
Copy link
Author

iamyoki commented Jul 21, 2022

@mitchellhamilton Thank you for your answer~
Deep down, It's expected and logical, but as a user-end, it's hard to find out what's wrong, it cost me several hours...
So I think it's better to support .babelrc format or shows explicit error or give a warning on doc site, would you like me to fix that?

@emmatown
Copy link
Member

A PR to add something to the docs site would be great

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

No branches or pull requests

2 participants