nodyn/jvm-npm

Can not invoke method ...findResource(String,boolean) with the passed arguments; they do not match

Closed this issue · 9 comments

I am trying to load my little library picolog in Nashorn using this awesome library (thank you btw!) but unfortunately it's not working. I get:

javax.script.ScriptException: TypeError: Can not invoke method [jdk.internal.dynalink.beans.SimpleDynamicMethod URL org.jboss.modules.ModuleClassLoader.findResource(String,boolean)] with the passed arguments; they do not match any of its method signatures. in vfs:/.../jvm-npm.js at line number 240

I peeked at line 240 and it's indeed a call to findResource but with only one argument...

I'm very new to Nashorn so I have no idea what to do now... Could this be an error in my script?

(btw, I know my library won't run (yet) in Nashorn, but I want to try to run it so I can fix it)

Forgot to mention: My code is running inside a servlet in WildFly 10.

I think this is the method that it cannot call:
http://docs.jboss.org/jbossmodules/1.2.0.Final/api/org/jboss/modules/ModuleClassLoader.html

I see that on Java's ClassLoader, findResource is protected:
http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#findResource(java.lang.String)

Could this be the problem? I think on Rhino calling protected methods was possible but I'm not sure.

Is Nashorn a 'supported platform' for jvm-npm?

I see that there is a getResource which is public:
http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)

The docs sound promising:

Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.
The name of a resource is a '/'-separated path name that identifies the resource.

This method will first search the parent class loader for the resource; if the parent is null the path of the class loader built-in to the virtual machine is searched. That failing, this method will invoke findResource(String) to find the resource.

I interpret this as 'does exactly the same as findResource, but searches parent classloaders first'. I'm not sure whether that would be a problem?
I'm forking your code to experiment a bit with this...

This small change seems to fix it. However now I get 'module not found' even though picolog is in the NPM registry.

I am using this library standalone but I'm starting to wonder whether I am doing it all wrong. Anyways, I'll stop ranting now :) Looking forward to your response.

lance commented

@Download can you provide a reproducible, failing test case for your module not found issue? If so, I will take a look. This hasn't been formally (or even informally as far as I know) tested against WildFly. I have suspicions this may be the culprit. Nashorn should definitely be supported. Glad you are finding this useful.

Ok I will try... if you promise to re-open when I do :)

Question: Where does jvm-npm expect the node_modules folder?
I just realized in my total n00biness I probably completely messed that part up...

lance commented

@Download node_modules is typically in the project directory, but jvm-npm should search all of the locations that standard npm does.

But what does 'the project directory' mean in the context of Nashorn running on WildFly? The 'current working directory'? The web root (webapp folder)?