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

Babel 7 + babel-preset-react-app@next but with TypeScript #3863

Closed
oieduardorabelo opened this issue Jan 18, 2018 · 9 comments
Closed

Babel 7 + babel-preset-react-app@next but with TypeScript #3863

oieduardorabelo opened this issue Jan 18, 2018 · 9 comments

Comments

@oieduardorabelo
Copy link
Contributor

Hello there 👋 ,

I'm trying to unify my building, currently TypeScript & Babel, under Babel 7,

I'm using babel-preset-react-app@next, to keep everything nice and updated, but, when I try to mix with @babel/preset-typescript, I've the following error:

Module build failed: Error: Cannot combine flow and typescript plugins.

screen shot 2018-01-19 at 12 44 13 pm

Seems it's because we've the @babel/preset-flow built in in babel-preset-react-app,

My questions is:

  • Could babel-preset-react-app make a opt-in/out for @babel/preset-flow?

How to reproduce

Keep in mind, below, there's no tsconfig.json yet, because the project doesn't even compile with both presets describe above

  • package.json file:
  "dependencies": {
    "@babel/core": "^7.0.0-beta.38",
    "@babel/preset-typescript": "^7.0.0-beta.38",
    "babel-loader": "8.0.0-beta.0",
    "babel-preset-react-app": "next",
    "babel-runtime": "^6.23.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "webpack": "^3.10.0"
  }
  • .babelrc
{
  "presets": ["react-app", "@babel/typescript"]
}

  • webpack.config.js
const path = require("path");

module.exports = {
  entry: "./main.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "dist")
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
};
  • main.js
import React from "react";
import ReactDOMServer from "react-dom/server";

const App = () => <h1>Hello Wolrd!</h1>;

console.log(ReactDOMServer.renderToString(<App />));
@gaearon
Copy link
Contributor

gaearon commented Jan 19, 2018

I wouldn't mind making it possible to exclude the flow preset with an option (but leave it on by default). Wanna send a PR?

@oieduardorabelo
Copy link
Contributor Author

oieduardorabelo commented Jan 19, 2018

sure @gaearon, what do you think about:

  • .babelrc
{
  "presets": [
    ["react-app", { useFlowPreset: false }],
    "@babel/typescript"
  ]
}

similar to how we use useBuiltIns

@Timer
Copy link
Contributor

Timer commented Jan 19, 2018

Looks good to me @oieduardorabelo. Do we know if there's an existing setting anywhere else so we can keep a consistent option name?

@oieduardorabelo
Copy link
Contributor Author

oieduardorabelo commented Jan 19, 2018

thanks @Timer, based on the docs, there are different options and configs, the only one I found similar to opt-in/out was useBuiltIns:

maybe the the last link is similar too, where we can toggle es2015 preset by es2015: false:

{
  "presets": [
    ["latest", {
      "es2015": false
    }]
  ]
}

following that, we could use:

{
  "presets": [
    ["react-app", {
        "flow": false 
    }],
  ]
}

@Timer
Copy link
Contributor

Timer commented Jan 19, 2018

I think "flow": false is best then 😄

@gaearon
Copy link
Contributor

gaearon commented Jan 19, 2018

Fixed in #3865

@gaearon gaearon closed this as completed Jan 19, 2018
@bondz
Copy link
Contributor

bondz commented Jan 19, 2018

Does this mean CRA supports React with typescript natively? 🕺

@gaearon
Copy link
Contributor

gaearon commented Jan 19, 2018

I doubt that :-). But if you can reuse the preset I guess that's nice?

@Timer
Copy link
Contributor

Timer commented Oct 30, 2018

TypeScript is now officially supported as of Create React App 2.1. Read the release notes to get started!

@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants