Using the Flow Type Checker
This feature is supported in the Ultimate edition only.
IntelliJ IDEA provides basic support of Flow static type checker that brings type annotations to JavaScript. This support involves recognition and syntax highlighting of Flow structures on all operating systems. If you are using Unix or macOS, you can also run Flow in the command-line mode.
On this page:
- Before you start
- Installing Flow
- Installing Flow globally
- Installing Flow in a project
- Configuring Flow in IntelliJ IDEA
Before you start
- Install and enable the NodeJS repository plugin as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
- Download and install the Node.js runtime environment.
- Configure the Node.js interpreter in IntelliJ IDEA:
- Open the by choosing for Windows and Linux or for macOS, and click Node.js and NPM under Languages & Frameworks.
- On the Node.js and NPM page that opens, specify the location of the desired Node.js interpreter.
Installing Flow
The easiest way to install the Flow type checker is to use the Node Package Manager (npm), which is a part of Node.js. See Installing and Removing External Software Using Node Package Manager for details.
Depending on the desired location of the Flow type checker executable file, choose one of the following methods:
- Install the type checker globally at the IntelliJ IDEA level so it can be used in any IntelliJ IDEA project.
- Install the type checker in a specific project and thus restrict its use to this project.
- Install the type checker in a project as a development dependency.
In either installation mode, make sure that the parent folder of the Flow type checker is added to the PATH
variable. This enables you to launch the type checker from any folder.
IntelliJ IDEA provides user interface both for global and project installation as well as supports installation through the command line.
Installing Flow globally
Global installation makes a type checker available at the IntelliJ IDEA level so it can be used in any IntelliJ IDEA project. Moreover, during installation the parent folder of the type checker is automatically added to the PATH
variable, which enables you to launch the type checker from any folder.
- Run the installation from the command line in the global mode:
- Launch the embedded Terminal ( or by hovering your mouse pointer over
in the lower left corner of IntelliJ IDEA and choosing Terminal from the menu
- Switch to the directory where NPM is stored or define a
PATH
variable for it so it is available from any folder, see Installing NodeJs. - Type the following command at the command line prompt:
npm install -g flow-bin
The
-g
key makes the type checker run in the global mode. Because the installation is performed through NPM, the Flow type checker is installed in thenpm
folder. Make sure this parent folder is added to thePATH
variable. This enables you to launch the type checker from any folder.For more details on the NPM operation modes, see npm documentation. For more information about installing the Flow type checker, see https://npmjs.org/package/flow-bin.
- Launch the embedded Terminal ( or by hovering your mouse pointer over
- Run NPM from IntelliJ IDEA using the Node.js and NPM page of the Settings dialog box.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click Node.js and NPM under Languages & Frameworks.
- On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click
.
- In the Available Packages dialog box that opens, select the required package to install.
- Select the Options check box and type
-g
in the text box next to it. - Optionally specify the product version and click Install Package to start installation.
Installing Flow in a project
Local installation in a specific project restricts the use of a type checker to this project.
- Run the installation from the command line:
- Run NPM from IntelliJ IDEA using the Node.js and NPM page of the Settings dialog box.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click Node.js and NPM under Languages & Frameworks.
- On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click
.
- In the Available Packages dialog box that opens, select the required package.
- Optionally specify the product version and click Install Package to start installation.
Project level installation is helpful and reliable in template-based projects of the type Node Boilerplate or Node.js Express, which already have the node_modules
folder. The latter is important because NPM installs the Flow type checker in a node_modules
folder. If your project already contains such folder, the Flow type checker is installed there.
Projects of other types or empty projects may not have a node_modules
folder. In this case npm goes upwards in the folder tree and installs the Flow type checker in the first detected node_modules
folder. Keep in mind that this detected node_modules
folder may be outside your current project root.
Finally, if no node_modules
folder is detected in the folder tree either, the folder is created right under the current project root and the Flow type checker is installed there.
In either case, make sure that the parent folder of the Flow type checker is added to the PATH
variable. This enables you to launch the type checker from any folder.
For more details, see Getting Started with Flow.
Configuring Flow in IntelliJ IDEA
To have IntelliJ IDEA recognize Flow structures, provide correct syntax highlighting, report errors properly, and avoid false-positive error highlighting, change the JavaScript language level to Flow, add a .flowconfig
configuration file to your project, and supply every file to be checked with a // @flow
comment on top.
- To change the language level to Flow:
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click JavaScript under Languages & Frameworks.
- On the JavaScript page that opens, choose Flow from the JavaScript Language Version drop-down list.
- In the Flow executable field, specify the path to the Flow executable file.
- In the Use Flow server for: area, specify the basis for coding assistance by selecting or clearing the following check boxes:
- Type checking: When this check box is selected, syntax and error highlighting is provided based on the data received from the Flow server. When the check box is cleared, only the basic internal IntelliJ IDEA highlighting is available.
- Navigation, code completion, and type hinting: When this check box is selected, suggestion lists for reference resolution and code completiong contain both suggestions retrieved from integration with Flow and suggestions calculated by IntelliJ IDEA. When the check box is cleared, references are resolved through IntelliJ IDEA calculation only.
- Code highlighting and built-in inspections: Select this checkbox to power native Flow code highlighting and built-in inspections. Please note that enabling this option may cause performance problems. By default, the check box is cleared.
The check boxes are available only when the path to the Flow executable file is specified.
- To have a
.flowconfig
configuration file generated in your project: launch the embedded Terminal ( or by hovering your mouse pointer overin the lower left corner of IntelliJ IDEA and choosing Terminal from the menu and run the
flow init
command at the command line prompt. - To have a file checked with the Flow checker, add a
// @flow
comment at the top of it: just typeflow
and press Tab and IntelliJ IDEA will expand it into// @flow
.