Skip to content
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

Ignore parse errors in .json files under node_modules/ #2364

Open
Macil opened this issue Aug 29, 2016 · 11 comments
Open

Ignore parse errors in .json files under node_modules/ #2364

Macil opened this issue Aug 29, 2016 · 11 comments
Labels

Comments

@Macil
Copy link
Contributor

Macil commented Aug 29, 2016

An issue I run into weirdly fequently (just ran into it again yesterday while adding Flow support to Kefir) is that some dependency or sub-dependency of a project contains purposefully malformed JSON files (some examples: bower-json/test/pkg-bower-json-malformed/bower.json, config-chain/test/broken.json, npmconf/test/fixtures/package.json), and Flow tries to parse them and reports errors.

I worked around it by adding some [ignore] lines to the .flowconfig, but I think it's bad when I have to configure something specifically to deal with a sub-dependency that I didn't even explicitly choose myself. I figured I'd go through and send a bunch of pull requests to get these modules to npmignore their test/ directories, but some of them are opinionated about putting their tests on npm, and some are in code freeze and not accepting pull requests (coincidentally these are 2/3 of the modules mentioned in #869 (comment); the commenter said they wanted to fix this, but without cooperation from those projects, the fix is going to have to come from Flow).

In the past, Flow had the similar/superset issue that it would try to parse all .js and .json files in the directory tree and it would report parse errors in all of them. The issue was lessened by Flow being changed to only do this with .js files that had the @flow comment and all .json files. Flow no longer assumes that all .js files under node_modules are parseable by it, but it still assumes that all .json files are.

This feature request can be seen as a much more restricted form of #869 that solves most of the issue that prompted that request.

@xjamundx
Copy link

Yes this got me as well. Any way this can be disabled by default?

@jedwards1211
Copy link
Contributor

Forgive me if this is a dumb question, but why does Flow parse .json files (besides package.json) to begin with?

@vkurchatkin
Copy link
Contributor

@jedwards1211 Flow does this to support requireing .json files

@jedwards1211
Copy link
Contributor

@vkurchatkin I'm not sure I understand why it needs to actually parse them to do that though. For instance it doesn't give me any errors if I try to use the version from package.json as a number:

// @flow

var version: number = require('./package.json').version

I assume it does parse package.jsons for things like "main": "src/index.js" though. But that wouldn't explain why it's parsing other .json files.

@Macil
Copy link
Contributor Author

Macil commented Jan 18, 2017

Any new feedback on this idea? #869 still gets a lot of user attention, and this is possibly a cleaner and easier to implement solution that solves the issues of most if not all commenters there. (I seem to be the only one ever talking about @flow files existing under node_modules; for modules without Flow types, the only thing that causes errors is malformed JSON files.)

If the solution sounds too over-specific, then maybe a better phrasing of it is "Only report parse errors in @flow files". (The node_modules-specific part could be optional.)

@ericsoco
Copy link

ericsoco commented Jun 1, 2017

For someone attempting to integrate Flow into an existing project as his first experience with Flow, this leaves me with a bad taste...would be great to get some maintainer eyeballs on this.

@pietrofxq
Copy link

+1, Flow is parsing a bower.json file that has a comment inside and is throwing errors for me.

@brandly
Copy link

brandly commented Mar 13, 2018

i'm running into this with electron-packager:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/electron-packager/test/fixtures/infer-malformed-json/package.json:3:1

Unexpected end of input

     1│ {
     2│   "productName": "InferMalformedJSON",
     3│

i don't understand why it still fails even when i explicitly [ignore] that file in my .flowconfig

@gordysc
Copy link

gordysc commented Apr 17, 2018

@brandly if you haven't solved this yet, you can accomplish this by doing something like this (notice the .* prefix):

[ignore]
.*/node_modules/electron-packager/test/fixtures/infer-malformed-json/package.json

@bsmith-cycorp
Copy link

Comically, Cypress has

node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/jsonlint/test/fails/

which is a directory full of nothing but JSON syntax errors... all of which Flow so-helpfully complains about.

@chrisbobbe
Copy link

chrisbobbe commented Jan 25, 2022

some of them are opinionated about putting their tests on npm

browserify/resolve#262 (comment) is an example of this:

@TrySound Tests are published in all my packages because npm explore foo && npm install && npm test should always work.

I think that might be reasonable? Here's a doc for npm test.

StevenXL added a commit to freckle/react-hooks that referenced this issue Apr 8, 2022
There is a purposely malformed `package.json` file in one of the
dependencies (for testing purposes). See issue:
facebook/flow#2364.
StevenXL added a commit to freckle/react-hooks that referenced this issue Apr 8, 2022
There is a purposely malformed `package.json` file in one of the
dependencies (for testing purposes). We are using `.flowconfig` to
ignore this file. See issue:
facebook/flow#2364.
facebook-github-bot pushed a commit to facebook/relay that referenced this issue Jul 22, 2022
…4023)

Summary:
flow check is failing on this repo right now

```
yarn run v1.22.19
$ flow check
Error --------------------------------------- node_modules/resolve/test/resolver/malformed_package_json/package.json:2:1
Unexpected end of input, expected the token `}`
   2|
Found 1 error
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 2.
```

I wish facebook/flow#2364 was addressed that I didn't have to do this :(

Pull Request resolved: #4023

Test Plan:
Imported from GitHub, without a `Test Plan:` line.

**Static Docs Preview: relay**
|[Full Site](https://our.intern.facebook.com/intern/staticdocs/eph/D38072807/V2/relay/)|

|**Modified Pages**|

Reviewed By: alunyov

Differential Revision: D38072807

Pulled By: voideanvalue

fbshipit-source-id: 0190e69a7fd61fa1ce3bcd73c57435ba14466235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests