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:- In a
node_modules
folder in the current directory - In a
node_modules
folder in any ancestor of the current directory - In the
js/node
,js/server/modules
orjs/server/common
folders of ArangoDB - In the internal
_modules
collection - In the base folder of the current Foxx service or module
- In a
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.
3 Comments
Leave a Comment
Get the latest tutorials, blog posts and news:
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
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.