home shape

Foxx Module Resolution Changes in ArangoDB 2.8

The implementation of the JavaScript require function will be adjusted to improve compatibility with npm modules. The current implementation in 2.7 and earlier versions of ArangoDB strictly adheres to the CommonJS module standard, which deviates from the behaviour implemented in Node and browser bundlers.

Module paths will now be resolved in the following ways:

  • relative paths (e.g. ./hello) will be resolved relative to the current file
  • absolute paths (e.g. /hello) will be resolved relative to the file system root
  • global names (e.g. hello) will be resolved by looking in the following places:
    1. In a node_modules folder in the current directory
    2. In a node_modules folder in any ancestor of the current directory
    3. In the js/node, js/server/modules or js/server/common folders of ArangoDB
    4. In the internal _modules collection
    5. In the base folder of the current Foxx service or module

Prior to 2.8 global names and absolute paths are being treated interchangeably and prioritize the service’s (or module’s) base folder, breaking compatibility with some dependencies like babel-runtime (which has both a submodule core-js as well as an npm dependency in node_modules/core-js).

Note that Foxx services generated with the web admin interface in 2.7 and earlier use global names instead of relative paths and may need to be adjusted in order to work with ArangoDB 2.8 and later. You should not use global names to refer to local files within your Foxx service (except for third party dependencies installed in the node_modules folder). You can safely replace such names with the appropriate relative paths in your Foxx code running on 2.7 and earlier.

Alan Plum avatar 1418721602 92x92

Alan Plum

Alan is an experienced web developer who feels equally at home in the backend and frontend. At ArangoDB he works on everything regarding JavaScript, with a special focus on Foxx.

3 Comments

  1. Alan Plum on December 14, 2015 at 11:18 am

    Foxx apps generated by ArangoDB 2.7 have requires like this in the controllers (e.g. /controllers/foo.js): require(‘repositories/foo’); in 2.8 it must look like this: require(‘../repositories/foo’). I’ve added an example to the upgrade notes: https://github.com/arangodb/arangodb/blob/2.8/Documentation/Books/Users/Upgrading/Upgrading28.mdpp

    • Paolo Zaccaria Carati on January 28, 2016 at 3:23 pm
      • Alan Plum on January 29, 2016 at 10:54 am

        Hi Paolo, please don’t add the “../” to other imports. “org/arangodb” is a global name, not part of your Foxx code. There’s no need to change it. You only need to change the generated imports of the repositories and models in the controllers.

Leave a Comment





Get the latest tutorials, blog posts and news: