Skip to main content
Version: 2.23 (prerelease)

Enabling Javascript support

How to enable Pants's bundled Javascript backend package.


Example Javascript repository

See here for examples of Pants's Javascript functionality.

Configuring the repository

Enable the experimental Javascript backend like this:

pants.toml
[GLOBAL]
...
backend_packages = [
"pants.backend.experimental.javascript"
]

Pants uses package_json targets to model a NodeJS package. Further, javascript_source and javascript_tests targets are used to know which Javascript files to run on and to set any metadata.

You can generate these targets by running pants tailor ::.

❯ pants tailor ::
Created project/BUILD:
- Add javascript_sources target project
- Add javascript_tests target tests
Improved inference and introspection for bundled projects

For dependency inference, Pants reads both your projects' package.json sections and additionally supports jsconfig.json, if one is present.

Setting up node

Pants will by default download a distribution of node according to the nodejs subsystem configuration. If you wish to instead use a locally installed version of, for example, 18.0.0 using nvm and its .nvmrc file, the following will get you there:

[nodejs]
known_versions = [] # Assign this to the empty list to ensure Pants never downloads.
version = "v18.0.0"
search_path = ["<NVM_LOCAL>"]

Setting up a package manager

To set a package manager project wide, do the following:

pants.toml
[nodejs]
package_manager = "pnpm" # or yarn, or npm.

you can instead opt to use the package.json#packageManager field for this setting. Regardless of setting, pants uses the corepack version distributed with the Node version you have chosen to install and manage package managers.