facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.08k stars 1.86k forks source link

Flow doesn't work with Lerna when importing packages into one another #5975

Open rjdlee opened 6 years ago

rjdlee commented 6 years ago

I have a Lerna package containing two different React apps made with Create React App (let's called them App A and App B). One of the apps imports the other one. I want to add Flow support to both apps. To do so, I've installed Flow at the global level.

Flow functions correctly when each app is used separately. However, when I import one of the apps into the other, I get the following error in App B:

Module parse failed: Unexpected token (8:5)
You may need an appropriate loader to handle this file type.
import { AppA } from 'app-a';

type Options = {
    key: string,
    onSuccess: function,

The way I interpret this is that Flow is not processing App A because it is a symlinked dependency (due to Lerna) inside App B. To resolve this, here is what I've tried:

I copy and pasted this from my question on Stack Overflow: https://stackoverflow.com/questions/49090460/using-flow-with-lerna-and-create-react-app#

rista404 commented 6 years ago

@rjdlee I think it would be helpful to state what version of Create React App you're using, since CRA is supporting Lerna only in their next version, specifically react-scripts@2.0.0-next.47d2d941. (https://github.com/facebook/create-react-app/issues/3815). Previous versions don't support Lerna, so that might be the issue.

However, there's still a question if it works in the next version of CRA. I'll test it out and report once https://github.com/facebook/create-react-app/issues/4154 is fixed.

If you're using the master version of CRA (1.x), you can try some solutions proposed here https://github.com/facebook/create-react-app/issues/1333, and see if it works.

rjdlee commented 6 years ago

@rista404 I'll update my CRA and let you know what happens. Thanks.

steelbrain commented 6 years ago

For all the people subscribed, a PR to fix this has been opened at https://github.com/facebook/flow/pull/6504

Please have a look (and maybe provide feedback)

matthewharwood commented 6 years ago

@steelbrain Looks like that PR isn't gonna be closed... Do you have any other ideas?

flo-pereira commented 5 years ago

I have this kind of configuration :

/packages
  package-a/
    dist/   // transpiled by babel
    src/
      index.js
      file-a.js
  package-b/
    dist/ 
    src/
      index.js
  createReactApp/
    src/
      index.js
    //...

/packages/createReactApp/src/index.js

import packageA from 'package-a';
import fileA from 'package-a/dist/file-a';

/.flowconfig

module.name_mapper='package-a' -> 'package-a/src/index'
module.name_mapper='package-a\/dist/\(.+\)' -> 'package-a/src/\1'

it's working fine.

petro-shkuratenyuk commented 5 years ago

@flo-pereira do you have one flowconfig per whole project?

flo-pereira commented 5 years ago

only one flowconfig at root /.flowconfig