Tim Fairbrother
Tim Fairbrother

Reputation: 929

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

Upvotes: 11

Views: 1473

Answers (2)

Wicharek
Wicharek

Reputation: 301

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'

Upvotes: 2

Lewis Chung
Lewis Chung

Reputation: 2327

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'

Upvotes: 2

Related Questions