flow icon indicating copy to clipboard operation
flow copied to clipboard

Fails to resolve main property in package.json

Open dignifiedquire opened this issue 11 years ago • 12 comments

If I have a file with

/* @flow */
var ReactRouter = require('react-router');

flow will fail with:

path/to/file:2 lib
Required module not found

Changing the main property from lib in the package.json of react-router to be lib/index makes it work.

ref: https://github.com/facebook/flow/issues/46

dignifiedquire avatar Feb 24 '15 17:02 dignifiedquire

What is the underlying issue here? Seems like flow doesn't understand node/npm's index.js convention.

mjackson avatar Feb 24 '15 19:02 mjackson

@mjackson yes that is my current guess.

dignifiedquire avatar Feb 24 '15 19:02 dignifiedquire

I ran into this issue as well. After some testing, it seems that flow does understand index.js convention when requiring (relative) folders in code (i.e. require('./dir')), but it does not support the convention in main property of package.json.

pyryk avatar Feb 27 '15 07:02 pyryk

It seems that the issue is fixed 0.5.0

jqwn avatar Mar 09 '15 02:03 jqwn

Please reopen if this is still an issue.

samwgoldman avatar Jun 24 '15 00:06 samwgoldman

I see this error again with Flow 0.16.0. Seems to be tracked by #654 now.

tp avatar Sep 28 '15 14:09 tp

@samwgoldman, I'm seeing this in Flow 0.22.0 with the react-router package, which specifies its 'main' in the package json as just 'lib' instead of 'lib/index.js'.

mrmurphy avatar Feb 23 '16 18:02 mrmurphy

Just upgraded from 0.21 -> 0.22 and seeing this bug.

EDIT: 0.22 started parsing .json files, so I added a regex to exclude them, which excluded package.json which caused the issue.

vjpr avatar Feb 29 '16 01:02 vjpr

This was fixed in 0.22.1, right?

dsilva avatar Mar 15 '16 09:03 dsilva

i'm seeing this error with flow-bin 0.29. every import that I do from node_modules is failing.

matiasfha avatar Jul 17 '16 04:07 matiasfha

just ran this test:

mkdir -p test/node_modules/foo/lib
pushd test
printf "// @flow\n\nmodule.exports = 'hello';\n" > node_modules/foo/lib/index.js
echo '{"name": "foo", "main": "lib"}' > node_modules/foo/package.json
printf "// @flow\n\n(require('foo'): number);\n" > index.js
touch .flowconfig
flow check
popd

and got this:

$ flow check
index.js:3
  3: (require('foo'): number);
      ^^^^^^^^^^^^^^ string. This type is incompatible with
  3: (require('foo'): number);
                      ^^^^^^ number


Found 1 error

so I think it's working now (v0.32)

mroch avatar Sep 16 '16 18:09 mroch

Just bumped into this again. Do NOT add this to your .flowconfig:

[ignore]
.*/node_modules/.*\.json$

vjpr avatar Nov 03 '18 12:11 vjpr