Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module error #45

Closed
morfeusys opened this issue Mar 31, 2016 · 8 comments
Closed

Cannot find module error #45

morfeusys opened this issue Mar 31, 2016 · 8 comments

Comments

@morfeusys
Copy link

Hi! I have js verticle and package.json contains:

{
  "name" : "npm-test",
  "dependencies" : {
    "figlet" : "1.1.1"
  }
}

npm-test.js file contains:

var figlet = require('figlet');

exports.vertxStart = function() {
    figlet('Hello World!!', function(err, data) {
        if (err) {
            console.log('Something went wrong...');
            console.dir(err);
            return;
        }
        console.log(data)
    });
};

After npm install I'm trying to run vertx run npm-test.js but this puts "Cannot find module fs" error in my console.
Of course my $NODE_PATH points to the right node's installation dir.
What should I do to resolve this issue?

@cescoffier
Copy link
Member

Could you provide a reproducer ?

@morfeusys
Copy link
Author

@cescoffier Sorry, didn't get it.. I've provided both js script and package.json files to reproduce it. What else have I to do?

@cescoffier
Copy link
Member

If you can come up with a githup project with these files and a readme file with the instructions like:

  • launch it with vertx run ....
  • Expected output
  • Current output

That would save us some time.

@ejmurra
Copy link

ejmurra commented Apr 12, 2016

@cescoffier Not OP but I'm having this issue too. Here's a reproducer: https://github.com/ejmurra/error_reproducer_vertx.git

It seems that top level require statements such as require('request') error out when the requested module makes another request for a peer dependency (in this case node_modules/request/index.js:17).
I'm running OSX 10.10.5

@cescoffier
Copy link
Member

Thanks ! Gonna have a look.

@pmlopes
Copy link
Member

pmlopes commented Apr 13, 2016

vert.x javascript is not based on node, even though we can load node modules once a module requires a native node such as fs or http (as required by express and request) in the reports it won't run.

vert.x uses nashorn to run scripts as long as your node modules are pure javascript without using any node API they should work. For example you can run template engines like handlebars, react or any module you could run on a browser.

@ejmurra
Copy link

ejmurra commented Apr 13, 2016

@pmlopes That makes sense to me.

What confuses me is that the error is thrown here which points to this file which has no dependencies (native node modules or otherwise). This leads me to think that nashorn is tracing the require('request') line to the request module in node_modules but any require calls after that are no longer looking in the node_modules directory.

@pmlopes
Copy link
Member

pmlopes commented Apr 19, 2016

You have a corrupted node_modules directory. From your reproducer, I've deleted the directory node_modules and re-download the dependencies with:

npm install

After that I run your example:

npm start

And got the error:

[plopes@heimdall error_reproducer_vertx]$ npm start

> [email protected] start /home/plopes/Projects/error_reproducer_vertx
> ./node_modules/.bin/vertx run server.js

javax.script.ScriptException: Error: Cannot find module net in <eval> at line number 141 at column number 6
    at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at io.vertx.lang.js.JSVerticleFactory$JSVerticle.start(JSVerticleFactory.java:109)
    at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$163(DeploymentManager.java:429)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$18(ContextImpl.java:335)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    at java.lang.Thread.run(Thread.java:745)
Caused by: <eval>:141:6 Error: Cannot find module net

And this leads back to what I've written before, net is a node.js core module, you cannot see it on vert.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants