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

Configuration for React Native #229

Open
3 of 10 tasks
terreb opened this issue Jul 1, 2019 · 4 comments
Open
3 of 10 tasks

Configuration for React Native #229

terreb opened this issue Jul 1, 2019 · 4 comments
Labels

Comments

@terreb
Copy link

terreb commented Jul 1, 2019

This is a:

  • Bug Report
  • Feature Request
  • Question
  • Other

Which concerns:

  • flow-runtime
  • babel-plugin-flow-runtime
  • flow-runtime-validators
  • flow-runtime-mobx
  • flow-config-parser
  • The documentation website

What is the current behaviour?

require is not defined on app start up


What is the expected behaviour?

App starts correctly


Which package versions are you using?

react-native: 0.57.8
flow-runtime: 0.17.0
babel-plugin-flow-runtime: 0.19.0

.babelrc

{
  "presets": [
    "module:metro-react-native-babel-preset",
    "@babel/preset-flow",
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    [
      "@babel/plugin-transform-flow-strip-types"
    ],
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ],
    [
      "flow-runtime",
      {
        "assert": true,
        "annotate": true,
        "optInOnly": true
      }
    ],
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-syntax-import-meta",
    "@babel/plugin-proposal-json-strings",
    "@babel/plugin-proposal-function-sent",
    "@babel/plugin-proposal-export-namespace-from",
    "@babel/plugin-proposal-numeric-separator",
    "@babel/plugin-proposal-throw-expressions"
  ]
}

I haven't found a correct configuration for react-native 0.57+ and babel 7 on Internet. This might be me doing something wrong. I tried my best to convert the configuration from here to use with react-native and babel 7 though.

@terreb
Copy link
Author

terreb commented Jul 1, 2019

There is another similar issue #205, but as I see the error is different and configuration there seems to be for Babel 6.

@terreb
Copy link
Author

terreb commented Jul 1, 2019

An update, if I remove:

    [
      "@babel/plugin-transform-flow-strip-types"
    ]

... from .babelrc, then I get Unexpected token { on app start up instead of the error above.

@terreb
Copy link
Author

terreb commented Jul 9, 2019

Ok, the issue is with import type and restructuring. Here is a piece of code where it fails:

import type {
    ____ViewStyleProp_Internal as ViewStyleType,
    ____TextStyleProp_Internal as TextStyleType,
    ____ImageStyleProp_Internal as ImageStyleType,
} from 'react-native/Libraries/StyleSheet/StyleSheetTypes'

which gets transformed into:

import { ____ViewStyleProp_Internal as _ViewStyleType, ____TextStyleProp_Internal as _TextStyleType, ____ImageStyleProp_Internal as _ImageStyleType } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';

I have import + restructuring all over the code, but only in this place where I have import type it's not transformed. If I remove flow-runtime it gets transformed correctly. How do I change my .babelrc to first transform import type {} into es5 and only then have it processed by flow-runtime?

@terreb
Copy link
Author

terreb commented Jul 9, 2019

The reason it's not working only in that place is because I have // @flow-runtime pragma only in that file, so only that one is being processed by flow-runtime. Now, my question is why imports and destructuring are not transpiled by babel if I enable flow-runtime for that file?

@gajus gajus added the question label Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants