New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flow is trying to parse JSON files as JS #1420
Comments
Still happening with the 0.22 release. |
0.21 was okay i only got this problem on 0.22 |
A temporary solution is to ignore the JSON files:
|
@jamiter unfortunately that seems to cause flow to ignore |
for reference this was the regex I ended up with in my
(as far as I can tell Ocaml regexps don't support negative look-behind) |
Yep. 0.21 worked fine. 0.22 is b0rked. The only work-around I can find is what @grncdr suggests: explicitly ignoring all of the json files in node_modules/ except package.json files. |
@grncdr, thank you! That explained those unresolvable errors! (Duh) Finally have it all working again. This bug of course still needs to be fixed. I shortened it for myself:
This found all the json files I was having issues with. The first line prevents package.json files to be ignored. |
FYI: I just landed #1436 -- which lets Flow parse JSON files that have toplevel array structures (rather than just toplevel object structures). Based on the error in the OP here, I think that should fix the error that caused that issue! |
@jamiter unfortunately none of these absurd workarounds work if you use a module with a name like |
@jedwards1211, it indeed is not an ideal solution, but they are working on a fix. You can tweak the regex a little to make it work for you. This should solve your issue:
The extra slash will make sure that |
With #1436, it will still fail when a module imports an invalid JSON file (e.g. for a test). |
Note: had to revet `flow-bin` to v0.21.0, because of a current bug where JSON files generate Flow errors: facebook/flow#1420 Once this bug has been fixed, we can bump the version beyond 0.22.0.
@eyko Yeah, in that case your best bet is to add a pattern targeting those files to the [ignore] section of your .flowconfig. We're looking into fixes that would require zero user intervention as well. |
You might also consider opening an issue with those module authors, informing them that they are including tests in their npm package, which they probably didn't intend to do. |
I am getting a related error for malformed JSON, e.g.
In this case, |
A small repo to demonstrate: https://github.com/grncdr/flowtest, running
flow status
produces the following output:This happens on the current master: 0792714, I don't know when it was introduced. It currently breaks flow for most any project using a non-trivial amount of npm packages, as these often have static JSON files for test fixtures and whatnot that flow will now find and break on.
Other than that, the intersection & union type fixes in
master
are awesome! Keep up the great work on Flow! ❤️ ❤️The text was updated successfully, but these errors were encountered: