banner



Npm How To Install Dependencies

npm, pnpm, and Yarn

WebStorm integrates with the npm, Yarn, Yarn 2, and pnpm, so you can install, locate, update, and remove packages of reusable code from inside the IDE, in the built-in Terminal.

WebStorm as well lets you run and debug npm, Yarn, and pnpm scripts. WebStorm parses packet.json files, recognizing definitions of scripts, shows scripts in a tree view, and lets you navigate between a script in the tree and its definition in the parcel.json file. See npm, Yarn, and pnpm official spider web sites for details.

WebStorm detects projects with Yarn workspaces and indexes all the dependencies that are listed in the package.json files of the workspaces just are located in the root node_modules folder.

WebStorm indexes all the dependencies listed in different package.json file but stored in the root node_modules folder

Earlier you first

  • Download and install Node.js. Note that npm is also installed, and then if you are going to use it, you are through with the preliminary steps.

  • To use Yarn, install it as described on the Yarn official website.

  • To use pnpm, open up the embedded Final (Alt+F12) and blazon:

    npm install --g pnpm

    Acquire more from the pnpm official website.

Choose a project package director

With WebStorm, you lot can choose whether to apply npm, Yarn, Yarn 2, or pnpm in a project.

By default, WebStorm suggests npm. However if you open up a project with a yarn.lock file and Yarn is installed on your computer, WebStorm automatically changes the packet manager for this project to Yarn.

Accordingly, if you open a projection with a pnpm-lock file and pnpm is installed on your estimator, WebStorm automatically changes the package director for this project to pnpm.

You can besides set Yarn 1 or pnpm as default WebStorm package manager.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), get to . The Node.js page opens.

  2. In the Package manager field, specify the package manager for your projection.

    Select project package manager: choose the default system installation
    • Select npm, yarn, or pnpm to apply the system default installation.

    • To employ a custom installation of a package manager, click Select, and select the installation folder of the relevant package manager.

      Select project package manager: choose a custom installation

    WebStorm automatically uses the chosen package manager when you select the Projection allonym from the Package director listing in the Run/Debug Configuration: NPM dialog. WebStorm as well uses the path to the chosen parcel manager every fourth dimension you invoke the Run 'npm install'/Run 'yarn install'/Run 'pnpm install' command or run an npm/Yarn/pnpm script, see Running and debugging scripts for details.

Ready Yarn two in your project

  1. Make sure you have Yarn 1 installed globally and enable Yarn 2 in your project as described on the Yarn official website. Use the embedded Concluding Alt+F12 to type the commands.

  2. In the Settings/Preferences dialog (Ctrl+Alt+S), become to and select the path to the Yarn ii package in your project from the Package managing director list.

Set Yarn 1 or pnpm every bit the default WebStorm package manager

  1. Open the Settings for New Projects dialog () and get to .

  2. On the Node.js and NPM folio that opens, select yarn or pnpm from the Package manager list.

Subsequently that, WebStorm will advise the selected packet director (Yarn or pnpm) as default every time you create a new project.

Edit package.json

WebStorm helps y'all handle your project dependencies in parcel.json files providing extensive coding help.

  • Code completion for parcel names.

    Code completion for package names
  • Information on the latest bachelor package version.

    Showing the latest available package version
  • Data about the range of versions that tin can be installed through npm install <bundle>@<version> or yarn add <package>@<version>. `Note that running npm install or yarn install will install the latest available version from this range.

    Press Ctrl and hover over the version to see the information in a tooltip. Meet the npm Official documentation for details well-nigh semantic versioning.

    Showing the range of available package versions
  • Code completion for previous packet versions. When you lot press Ctrl+Space or start typing a version unlike from the latest one, WebStorm displays a suggestion list with all the previous versions of the packet.

    Code completion for previous package versions
  • Quick documentation look-up for packages.

    Quick documentation look-up for packages

Install and update packages

As you may know, npm can install packages both globally or as project dependencies or development dependencies, learn more from the npm official website.

pnpm also installs packages globally or every bit project dependencies or development dependencies, larn more from the pnpm official website.

With Yarn, you tin install packages globally or as project dependencies, see Yarn official website for details.

In WebStorm, packages can be installed in the editor, from a parcel.json file, in the congenital-in Terminal Alt+F12, or on the Node.js page.

From package.json

Install your project dependencies

  • Click the Run 'npm install', Run 'yarn install', or Run 'pnpm install' link in the popup:

    Install dependencies popup

    WebStorm shows this popup when the dependencies are not installed yet or when they accept changed. If yous close the popup or plow it off by choosing Don't ask again, you can nevertheless install the dependencies using the Run '<package_manager> install' action or in the built-in terminal.

    If you take accidentally dismissed this notification and now want to get it back, press Ctrl+Shift+A, starting time typing Enable notifications, and select Enable Notifications about Installing Dependencies from parcel.json from the list.

  • Alternatively, open the relevant package.json file in the editor or select it in the Project tool window and choose Run 'npm install' from the context bill of fare.

Update your project dependencies

  • Click Run '<package director> install' in the popup.

    Update dependencies: popup

    WebStorm shows this popup every fourth dimension you open a projection, update it from the version control, or edit a package.json.

  • WebStorm too runs an inspection that checks whether the packages from dependencies or devDependencies are installed and their versions match the specified range. If the inspection detects whatsoever mismatch, information technology suggests a quick-set. To utilize information technology, click the Run '<packet director> install' link.

    Installed version of a package is not up to date
  • WebStorm also detects packages for which later versions are available and provides a quick-fix when you hover over the package version.

    Update package to latest version: tooltip

    Alternatively, press Alt+Enter and select Update <packet> to the latest version from the list:

    Update package to latest version: quick-fix

In the built-in Terminal

In the embedded Last (Alt+F12) , type i of the following commands:

  • For global installation:

    • npm install --global <package_name>

    • yarn global add <package_name>

    • pnpm --global add <package_name>

  • To install a package every bit a project dependency or a development dependency:

    • npm install --salve <package_name> or npm install --save-dev <package_name>

    • yarn add <package_name> --dev

    • pnpm add --save-dev <package_name>

Install all dependencies listed in a package.json file

In the embedded Concluding (Alt+F12) , blazon one of the following commands:

  • npm install

  • yarn install

  • pnpm install

As a result y'all get all the dependencies listed in the package.json from the current folder. Larn more from Editing package.json.

Run and debug scripts

You tin can launch npm, Yarn, or pnpm scripts from a parcel.json file in the editor, from a tree of scripts in the defended npm tool window, according to a dedicated run configuration, or automatically, every bit a start-upwardly or a before-launch chore.

The results of script execution are displayed in the Run tool window. The tool window shows the npm or Yarn script output, reports the errors occurred, lists the packages or plugins that have not been found, etc. The proper noun of the last executed script is displayed on the title bar of the tool window.

Running a script: Run tool window

If you launch a script debugging session, WebStorm opens the Debug tool window.

Debugging a script: Debug tool window

During a script debugging session, you lot can step through the script, stop and resume the script execution, examine it when suspended, run JavaScript code snippets in the Debugger Console, and and so on.

Run and debug scripts from package.json

WebStorm lets you chop-chop launch unmarried scripts from package.json files. To run or debug several scripts, utilise a run configuration or the npm tool window.

  • Open the bundle.json file in the editor, click the Run button in the gutter side by side to the script, and cull Run <script_name> or Debug <script_name> from the context carte du jour.

    Run/debug a script from package.json
  • You tin as well run a script by pressing Ctrl+Shift+F10.

The script output is shown in the Run tool window.

If you launch a script in the debug manner, WebStorm opens the Debug tool window, where you can stride through the script, end and resume the script execution, examine it when suspended, run JavaScript code snippets in the Debugger Console, and so on.

Run and debug scripts from the npm tool window

The npm tool window opens when you select a package.json file in the Project tool window or open it in the editor and select Prove npm Scripts from the context card.

As soon as you invoke npm, pnpm, or Yarn, the tool starts edifice a tree of scripts divers inside the scripts property of the package.json file on which it was invoked.

If you have several parcel.json files in your projection, you can build a separate script tree for each of them and run scripts without dropping the previously built trees. Each tree is shown nether a separate node.

Open the npm tool window if it is not opened nevertheless

  • Select the required file in the Project tool window or open it in the editor and cull Show npm Scripts from the context card.

    Open the npm tool window

    The npm tool window opens showing the scripts tree built according to the selected or opened package.json file.

Build a tree of scripts in an already opened npm tool window

  1. In the npm tool window, click the Add button on the toolbar and choose the required package.json file from the list. Past default, WebStorm shows the packet.json file in the root of your project.

  2. If you have another packet.json file, click Choose bundle.json and select the package.json file you lot demand in the dialog that opens. WebStorm 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.

Build another scripts tree

Re-build a tree

  • Switch to the required node and click Reload Scripts on the toolbar.

    Reload Scripts

Sort the scripts in a tree by their names

  • Click Settings on the toolbar, cull Sort by from the carte, and and so choose Name.

    Past default, a tree shows the scripts in the order in which they are defined in bundle.json (option Definition order).

    Sort scripts by name

Run ane script

  • Double-click the script.

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

Run one script from the npm tool window

Debug one script

  • Select the script in the tree and cull Debug <script_name> from the context menu.

    WebStorm opens the Debug tool window where y'all can step through the script, stop and resume the script execution, examine it when suspended, run JavaScript code snippets in the Debugger Console, and and then on.

Debug one script from the npm tool window

Run or debug several scripts

  • Employ the multiselect way: hold Shift (for adjacent items) or Ctrl (for not-side by side items) keys and select the required scripts, then choose Run or Debug from the context carte of the choice.

    Run multiple scripts

Run and debug scripts by a run configuration

When you lot run or debug scripts from the editor or from the npm tool window, WebStorm automatically creates temporary run configurations. Besides using them, you can create and launch your own npm run configurations.

  1. From the main menu, select . Alternatively, select Edit Configurations from the listing on the toolbar.

  2. Click the Add button on the toolbar and select npm from the list. The Run/Debug Configuration: npm dialog opens.

  3. Specify the CLI command to execute, the scripts to run (use blank spaces as separators), and the location of the package.json file where these scripts are defined. Optionally, type the command-line arguments for executing the scripts.

  4. Specify the Node.js interpreter to utilise. This can be a local Node.js interpreter or a Node.js on Windows Subsystem for Linux.

    Optionally, specify the Node.js-specific pick parameters and the environment variables to be passed to Node.js.

  5. Specify the package manager to use. If you lot choose the Project alias, WebStorm will utilise the default projection package manager from the Node.js page. Y'all tin can also choose the relevant package allonym (npm or yarn) or specify an explicit path to a custom installation of a package manager.

  6. Select the newly created run configuration from the list on the toolbar and and then click Run or Debug next to the list.

    The results of script execution are displayed in the Run tool window.

    If yous click Debug, WebStorm opens the Debug tool window, where you tin can step through the script, stop and resume the script execution, examine it when suspended, run JavaScript code snippets in the Debugger Console, and then on.

Run scripts with Run Anything

Run Anything is a quick style to start scripts.

  1. Printing Ctrl twice or click the Run Anything button on the Navigation bar. The Run Anything popup opens.

  2. Blazon npm run or yarn run in the search field. As yous type, WebStorm shows the matching scripts. Select the required i from the list and press Enter.

    Run Anything: npm script

    To view the command output in the Run tool window, press Ctrl+Enter, to show the output in the Debug tool window, press Shift+Enter.

    Running script in the Debug tool window from  the Run Anything popup

Run scripts automatically on start-up

If yous have some scripts that you run on a regular footing, you tin add the corresponding run configurations to a list of startup tasks. The tasks will be executed automatically on the projection start-up.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), become to .

  2. On the Startup Tasks page that opens, click the Add button on the toolbar.

  3. From the list, choose the required npm run configuration. The configuration is added to the list.

    If no applicable configuration is available in the project, click the Add button` and choose Edit Configurations. Then ascertain a configuration with the required settings on the Run/Debug Configuration: NPM folio that opens. When you save the new configuration it is automatically added to the listing of startup tasks.

Run scripts as before-launch tasks

  1. Open up the Run/debug configurations dialog dialog by choosing from the main card, and select the required configuration from the list or create information technology afresh by clicking Add New Configuration and choosing the relevant run configuration blazon.

  2. In the dialog that opens, click Add in the Before launch surface area and choose Run npm script from the list.

  3. In the NPM Script dialog that opens, specify the npm run/debug configuration settings.

npm, pnpm, and yarn in Docker

With WebStorm, you lot tin can edit parcel.json, install, update, and remove dependencies of a projection in a Docker container just in the same way every bit you do it locally.

  1. Make sure the Node.js, Node.js Remote Interpreter, and Docker required plugins are enabled on the Settings/Preferences | Plugins page, tab Installed, meet Managing plugins for details.

  2. Download, install, and configure Docker as described in Docker

  3. Configure a Node.js remote interpreter in Docker and set it is every bit default in your projection. Besides make sure the parcel manager associated with this remote interpreter is set as project default.

  4. Proceed every bit with local evolution: edit your package.json, manage y'all projection dependencies, and run or debug scripts.

Terminal modified: xv Nov 2022

Source: https://www.jetbrains.com/help/webstorm/installing-and-removing-external-software-using-node-package-manager.html

Posted by: rosexyle1976.blogspot.com

0 Response to "Npm How To Install Dependencies"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel