You are reading the documentation for an outdated Corteza release. 2024.9 is the latest stable Corteza release.

Using node modules

Corteza Corredor supports the use of external node modules, both on the server-scripts and client-scripts.

Corteza Corredor uses the Yarn package manager.

To add a new node module either:
  • manually insert it into the package.json file,

  • run the yarn add NAME_GOES_HERE.

When you register and load the extension in the Corredor server, it will automatically resolve any changed dependency from the package.json file.

We’re observing some anomalies when running Yarn inside a docker container.

If you’re getting an error message similar to the one below, it means that Yarn was not able to install the dependencies. This error occurs when Yarn is unable to store its cache.

{
  "type": "error",
  "data": "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: \\"ENOSPC: no space left on device, write\\""
}
To fix this, you need to:
  1. ssh into the Corredor container (docker-compose exec -u root corredor sh),

  2. cd into the mounted volume,

  3. run yarn --cache-folder /tmp.

The dependencies should now be installed and available for use. The above yarn command manually runs the install process, discarding the cache.

Node modules can then be used just like anywhere else.

Example package.json:
{
  "dependencies": {
    "axios": "^0.18.0"
  }
}
Example usage from automation scripts:
import axios from 'axios'

export default {
  // ...

  async exec() {
    await axios.get(...)

    // ...
  }
}

Different extensions do not share their dependencies. If two extensions use the same dependency, they both need to define it.