Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you get flow to work with babel module-alias?

I am trying to get flow to type check my code but it is giving me an error when it can't find paths that have been rewritten using babel-plugin-module-alias.

I have unsuccessfully tried to use the resolve_dirname option in the flowconfig.

Can someone please tell me if it is possible to use this babel plugin with flow?

.babelrc

{
  "plugins": [
    "transform-flow-strip-types",
    ["module-alias", [
      { "src": "./app", "expose": "app" },
    ]]
  ]
}

.flowconfig

[options]
module.system.node.resolve_dirname=app

app/main.js

import bar from 'app/foo';

app/main.js:3

  3: import bar from 'app/foo';
                     ^^^^^^^^^^ app/foo. Required module not found
like image 296
Tim Fairbrother Avatar asked Dec 12 '16 00:12

Tim Fairbrother


2 Answers

Here is how this can be achieved with module.name_mapper setting in .flowconfig [options]. Works in flow version 0.56.0

module.name_mapper='^app/\([-a-zA-Z0-9$_/]+\)$' -> '<PROJECT_ROOT>/src/\1'
like image 153
Wicharek Avatar answered Nov 04 '22 16:11

Wicharek


module.system.node.resolve_dirname actually tells Flow where to start resolving things from. If you want Flow to resolve starting from 'app', you need to point it one directory higher than app.

Alternatively, you can probably also use `module.name_mapper='^app/([a-z-A-Z0-9$_/]+)$' -> 'src/\1'

like image 37
Lewis Chung Avatar answered Nov 04 '22 17:11

Lewis Chung