Closed chefhoobajoob closed 8 years ago
Confirming that this is still an issue for 3.2.0
The only way I've found to get these to resolve correctly is to hand modify the .js
files in rql
and change all their require('./<something>')
statements to require('rql/<something>')
, which clearly isn't an acceptable workaround.
The issue comes from the construction of the "root" in which the module is searched. I'm going to publish a fix. It would be great if you could test it.
Can you check with https://github.com/vert-x3/vertx-lang-js/pull/42.
Confirming that this change results in a successfully resolved require statement.
@cescoffier: I'm finding that this fix only works for js files that aren't in sub-directories within the required node module directory.
For example, if the verticle requires a module script that resides in <project-root>/node_modules/myModule/js/myScript.js
and that script includes a require statement like so: require ('./myOtherScript.js');
, then 3.2.1 will also fail to resolve that statement with the same kind of exception.
I will try and update the reproducer for this with another simple example to illustrate.
@cescoffier: it seems that it's not to do with whether there are subdirectories under the node_module, but with the style of require
statement made from the verticle.
If you refresh the reproducer, I've updated it to illustrate which kinds of failure statements are failing on 3.2.1.
Basically, on 3.2.1, if an npm_module
has a package.json
which defines a main
property that specifies the path to the main script for the module, and the verticle includes a require
statement that only names the npm_module
, vertx will find the main script for the module, but will then fail to resolve require
statements found in that main script.
If instead the verticle's require
statement explicitly names the main script, vertx will find the main script and it will successfully resolve require
statements in the main script.
@cescoffier: let me know if I should just open a new issue for this one.
@cescoffier: I'll open a new issue for 3.2.1.
See issue #44
See reproducer here: https://github.com/chefhoobajoob/npm-verticle-reproducer
I have not been able to reproduce this problem on Mac or Linux variants, but it appears to be consistently failing on Windows systems.
I have a JS verticle with a single require statement referencing an expected npm dependency (rql in the example). I also have a launch script that ensures that NODE_PATH is set to the npm
node_modules
folder of the project so that therql
package is found.On both Linux and Windows systems, Vertx successfully resolves the
rql/js-array
require statement in the verticle's JS file, but therql/js-array
module itself contains anotherrequire
statement for./parser
, which is a JS file within thenode_modules/rql
folder.On Linux systems, the
require
statement for./parser
resolves successfully, on Windows systems, it fails with an exception: