Flow: Error when importing relative paths

Created on 21 Jan 2019  Β·  11Comments  Β·  Source: facebook/flow

Issue Summary

When importing certain relative path modules I get the following error;

[Flow] Cannot resolve module `../<file name>`. [InferError]

The file paths that Flow has this error for do exist.

To Reproduce

β”œβ”€β”€ src
β”‚   └── index.js <--- `import * from '../lib/foo'`
β”œβ”€β”€ lib
β”‚   └── foo.js
  1. Import a module from a different directory in a parent of files directory

I'm not 100% this isn't also caused in other local path patterns.

Further Information


Actual directory structure

|-cypress
|  | ... Cypress test files / folder ...
|-bin
|-gallery
|  |-components <--- `[Flow] Cannot resolve module `../lib/filename`. [InferError]`
|  |-data
|  |-docs
|  |-lib
|- node_modules
|  | ... all the modules ...
|-.github
|-lib
|  | ... built files ...
|-flow-typed
|  | ... flow typed modules ...
|-src
|  | ... main code ...



.flowconfig

[ignore]
.*/cypress/**/*
.*/lib/**/*
.*/node_modules/**/*
.*/docs/*

[include]

[libs]

[lints]

[options]
all=true

[strict]

Technical details:

  • Node Version: v9.11.2
  • OS: OS X 10.14

Possibly Related: https://github.com/facebook/flow/issues/6960

question

All 11 comments

What is your flowconfig and where do you keep it?

@TrySound thanks for the quick response.

.flowconfig is in the root of the project.

This is what we have;


.flowconfig

[ignore]
.*/cypress/**/*
.*/lib/**/*
.*/node_modules/**/*
.*/docs/*

[include]

[libs]

[lints]

[options]
all=true

[strict]

The problem could be that the lib folder is in your [ignore] section

@0rvar Thank you, I _just_ updated my comment as you posted this 😁The example tree structure in my post was for illustrative purposes only and doesn't reflect my exact use-case. Let me see if I can create a more comprehensive version.

Updated original post

I've added some additional information on the exact directory structure and config I'm seeing the error with.

@matthojo You ignored lib and flow cannot resolve to it. That's the problem.

@TrySound thanks, I’ll take a look in the morning - I _think_ this may also be happening for files outside of lib.
Out of interest does the β€˜lib’ folder exclusion in the flow config traverse sub-directories? I was only intending it on being β€˜lib’ in the project root.

So, I've looked into this again and there are other modules from other areas outside of lib causing errors.

One example;

|-cypress
|  | ... Cypress test files / folder ...
|-bin
|-gallery
|  |-components
|  |  |-isolated <--- `[Flow] Cannot resolve module `../../../src/Filename`. [InferError]`
|  |-data
|  |-docs
|  |-lib
|- node_modules
|  | ... all the modules ...
|-.github
|-lib
|  | ... built files ...
|-flow-typed
|  | ... flow typed modules ...
|-src
|  | ... main code ...

I have the exact same problem. I'm not ignoring any folder except stuff in node_modules.

It seems like flow is trying to resolve the module from the root folder of my project. e.g:

import { User } from '../../../models';

throws the following error:

Cannot resolve module /Users/20syl/Documents/models/index.js.

My folder architecture looks like this:

Users
 - 20syl
  - Documents
   - www
    - myApp
     - src
      - module
       - models
        index.js
       - components
        - MyComponent
         - SubComponent
          - index.js
        - MySecondComponent
         ... etc.

My app is very large and has tons of relative imports, which works well. For instance other files are importing the same file but work correctly.

also having this issue. Actually it's just when using Webstorm...if i run the "flow" command, the errors don't show up. Also if i control click the reference in webstorm (with the "use webstorm to resolve files" option clicked) it will bring me to the folder...so it can clearly resolve it.

Has anyone found the solution to this problem? I’m having this with

import image from "./assets/image.webp"

however PNG images from the same director work without an error.

import image from "./assets/image.png"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ctrlplusb picture ctrlplusb  Β·  3Comments

cubika picture cubika  Β·  3Comments

Beingbook picture Beingbook  Β·  3Comments

doberkofler picture doberkofler  Β·  3Comments

tp picture tp  Β·  3Comments