See reproducer here: https://github.com/chefhoobajoob/npm-verticle-reproducer
If a js verticle has a dependency on an npm module, and that module implementation includes require
statements for other scripts within the module, the module's require
statements will fail to resolve unless the verticle's require
statement explicitly specifies the full relative path to the module script that is required. This breaks module encapsulation, forcing clients to be dependent on the internal structure of the module's file system.
For example, assume a js verticle includes this require statement:
var m = require('myModule');
And, assume that there is a node_modules
folder containing a myModule
folder. In the myModule
folder is a package.json
file which includes this line:
And, assume that myMain.js
includes this require statement:
var l = require('./util')
Where 'util.js' is another file in the myModule
folder. vertx-lang-js
3.2.1 will correctly resolve require('myModule')
to that module's main script, myMain.js
, but in evaluating myMain.js
, vertx-lang-js
will fail to resolve its require('./util')
statement, and an exception will be thrown preventing the verticle from launching.
The only available workaround at the moment is for the verticle implementation to change its require statement to:
var m = require('myModule/myMain')
This is not the case when running the verticle on Linux or on OS/X, as far as I can tell. On those operating systems, vertx-lang-js
correctly resolves module require
statements when the verticle's require
statement only names the module and not the full path to the module's main script.
I'm not sure how deep this behavior goes. For example, a module can have its own node_modules
folder which contains yet more dependency implementations, which can each have their own require
statements, and this nesting could be arbitrarily deep.
It would be good to know that these nested module dependencies will each correctly resolve their respective require
statements in the right scope on all supported operating systems.