Skip to content

Prevent reading all node_modules when using [untyped] #7431

@vjpr

Description

@vjpr

I want import 'foo/bar' to not throw "cannot find module" errors, but want to prevent the server looking at all my node_modules.

With the current options there is no way to get this to work.

a.

[untyped]
.*/node_modules/.*

Problem: Dramatically slower server startup.

This makes the server scan all my node_modules. I have ~3000 project files, and 200K files in node_modules.

This means the server takes 1 minute to start versus instantly.

Instead of needing to read and watch every node_module file to ensure import 'foo/bar' is valid, just check whether the files exist during type checking process. But I would be fine with just ignoring the check of whether my imports are valid for node_modules too.

b. ignore

[ignore]
.*/node_modules/.*

Problem: "Cannot find module" errors for any import foo from 'foo'.

c. ignore all node_modules except first level of dirs

(Ignore all node_modules dirs except the first)

[ignore]
.*/node_modules/.*/.*/.*

# Needed for pnpm because Flow tests regexes on realpaths - see #7429 
.*/node_modules/\.registry\.npmjs\.org/.*/.*/node_modules/.*/.*/.*

Problem: import 'foo/bar' doesn't work.

d. declarations

[declarations]
.*/node_modules/.*

Problem: Still slow server startup - scans every file.

Problem: Errors are shown for all 3rd party modules with type annotations of which there are usually hundreds broken (e.g. graphql@0.13.2). This will happen perpetually because there will always be deprecations and new features, and flow doesn't have a way to version type annotations.

e. name_mapper for all non-relative requires

[ignore]
.*/node_modules/.*

[options]
# Match `import 'foo'` but not `import './foo'`.
module.name_mapper='^[A-Za-z]+.*' -> '<PROJECT_ROOT>/any.js.flow'

any.js.flow

// @flow
declare module.exports: any;

Doesn't scan or watch any node_modules. All package imports will be replaced with any type - just liked [untyped] does.

Problem: This doesn't work with a monorepo where import foo from 'foo' could refer to a symlinked package.

Problem: It's not flexible.


Solution

Add an option module.system.node.silence_module_not_found_errors_in_ignore_paths or something like that.

Related

a lot of us want type processing in node modules but NO errors shown in any node modules. We want errors to be shown in our own code when we missuse a module, but we don't want to see that any node modules did something wrong internally. We want to be able to maintain code that is error free and see that on a PR there are no flow errors, but we can't do that when node modules reports hundreds of errors for dependencies I can't control.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions