CLion 2018.2 Help

NPM Tool Window

Context menu of a package.json - Show npm Scripts
View | Tool Windows | npm

Use the tool window to run npm or Yarn scripts.

Before you start

  1. Install and enable the NodeJS repository plugin on the Plugins page as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
  2. Install Node.js. Note that npm is also installed so if you are going to use it you are through with the preliminary steps.
  3. To use Yarn, install it as described on the Yarn Official website.

Running scripts

The tool window opens when you select a package.json file in the Project tool window or open it in the editor and choose Show npm Scripts on the context menu. As soon as you invoke npm or Yarn, it starts building a tree of scripts defined within the scripts property of the package.json file on which it was invoked. If you have several package.json files in your project, you can build a separate script tree for each of them and run scripts without dropping the previously built trees. Each tree is shown under a separate node.

The tool window shows the script output, reports the errors occurred, lists the packages or plugins that have not been found, etc. The name of the last executed script is displayed on the title bar of the tool window.

To build a tree of scripts, do one of the following:

  • Select the required package.json file in the Project tool window or open it in the editor and choose Show npm Scripts on the context menu.
  • In the npm tool window, click icons general add on the toolbar and choose the required package.json file from the list. By default, CLion shows the package.json file in the root of your project. If you have another package.json file, click Choose package.json and select the package.json file you need in the dialog that opens. CLion adds a new node with the path to the chosen package.json file on its title and builds a scripts tree under the new node.

To re-build a tree

  • Switch to the required node and click icon_reload_grunt.png on the toolbar.

To sort the scripts in a tree by their names

  • Click viewMode.png on the toolbar, choose Sort by on the menu, and then choose Name.
    By default, a tree shows the scripts in the order in which they are defined in package.json (option Definition order).

To run one script

  • Double click the script.
  • Select the script in the tree and press Enter or choose Run <script name> on the context menu.

To run several scripts

  • Use the multiselect mode: hold Shift (for adjacent items) or Ctrl (for non-adjacent items) keys and select the required scripts, then choose Run or Debug on the context menu of the selection.

Toolbar

icons general add Add package.json Click this button to have a tree of scripts for another package.json file built. Choose the required package.json file from the pop-up list. CLion adds a new node and builds a tree of scripts under it it.
minusSign.png Remove package.json Click this button to remove the tree of scripts under the selected node.
icon_reload_grunt.png Reload scripts Click this button to have the tree of scripts under the selected node re-built. You may need a tree re-built after updating the corresponding package.json file because npm does not apply changes to trees on the fly.
icon_collapse_all_on_title_bar.png Collapse all Click this button to hide all the scripts trees and have only package.json nodes displayed.
viewMode.png Click this button to configure the current view and to change the viewing modes of the tool window, see Tool Windows Viewing Modes for details. Note that most of the menu items are options that you can turn on or off. An option which is on has a check mark to the left of its name. The npm-specific options are:
  • npm Settings: choose this menu item to open the npm Settings dialog and re-configure the current settings for npm and for the Node interpreter, see task runner.
  • Sort by: choose this menu item to configure the order in which scripts are shown in trees. Click viewMode.png on the toolbar, choose Sort by on the menu, and then choose Name.
    By default, a tree shows the scripts in the order in which they are defined in package.json (option Definition order).
hideSide.png Hide Click this button to hide the tool window. To have it displayed again, choose View | Tool Windows | npm on the main menu. The tool window appears again showing all the previously built trees of tasks.

Context Menu of a Tree

npm Settings Choose this menu item to open the npm Settings dialog box and view or edit the Node.js configuration
Jump to Source Choose this menu item to open the package.json file for which the current tree is built.
Reload scripts Choose this menu item to have the tree of scripts under the selected node re-built.
Copy Path Choose this menu item to save the path to the package.json file according to which the current tree was built to the clipboard.
Remove package.json Choose this menu item to remove the tree of scripts under the selected node.

Context Menu of a Script

Run <script name> Choose this menu item to run the selected script.
Edit <script name> settings Choose this menu item to open the Run/Debug Configuration dialog box and edit the predefined settings for the selected script.
Jump to Source Choose this menu item to open the package.json file for which the current tree is built and navigate to the definition of the selected script.
Last modified: 16 June 2018

See Also