apigee / trireme

Embed Node.js inside a Java Virtual Machine
Other
479 stars 48 forks source link

Unable to read node_modules with dependencies like "lodash" #192

Open niso1985 opened 5 years ago

niso1985 commented 5 years ago

I call to my_js_app/index.js using NodeScript following the code:

NodeScript script = env.createScript("index.js", new File("../../../my_js_app/index.js"), new String[]{"foo", "bar"});
script.execute().get();

my_js_app/index.js require lodash and commander etc.

const _ = require("lodash");
const program = require("commander");

And these node_modules is installed using "npm install".

The following error occurs when this program is executed.

16:10:36.010 [Trireme Script Thread] DEBUG io.apigee.trireme.core.internal.ScriptRunner - argv[0] = ./node
16:10:36.011 [Trireme Script Thread] DEBUG io.apigee.trireme.core.internal.ScriptRunner - argv[1] = ../../../my_js_app/index.js
16:10:36.011 [Trireme Script Thread] DEBUG io.apigee.trireme.core.internal.ScriptRunner - argv[2] = foo
16:10:36.011 [Trireme Script Thread] DEBUG io.apigee.trireme.core.internal.ScriptRunner - argv[3] = bar
16:10:36.049 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - open(/Users/ktsujino/projects/myapp/my_js_app/index.js, 0, 438)
16:10:36.049 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - Opening /Users/ktsujino/projects/myapp/my_js_app/index.js with [READ]
16:10:36.050 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem -   open(/Users/ktsujino/projects/myapp/my_js_app/index.js) = 4
16:10:36.107 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - open(/Users/ktsujino/projects/myapp/my_js_app/node_modules/lodash/index.js, 0, 438)
16:10:36.107 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - Opening /Users/ktsujino/projects/myapp/my_js_app/node_modules/lodash/index.js with [READ]
16:10:36.107 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem -   open(/Users/ktsujino/projects/myapp/my_js_app/node_modules/lodash/index.js) = 5
16:10:36.114 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - File system error java.nio.file.NoSuchFileException: /Users/ktsujino/projects/myapp/my_js_app/node_modules/lodash/lodash = code -2
16:10:36.116 [Trireme Script Thread] DEBUG io.apigee.trireme.node12.modules.Filesystem - I/O exception: -2: {}
io.apigee.trireme.kernel.OSException: ENOENT:/Users/ktsujino/projects/myapp/my_js_app/node_modules/lodash/lodash
    at io.apigee.trireme.kernel.fs.AdvancedFilesystem.stat(AdvancedFilesystem.java:337)
    at io.apigee.trireme.node12.modules.Filesystem$FSImpl.doStat(Filesystem.java:655)
    at io.apigee.trireme.node12.modules.Filesystem$FSImpl.access$500(Filesystem.java:84)
    at io.apigee.trireme.node12.modules.Filesystem$FSImpl$13.execute(Filesystem.java:630)
    at io.apigee.trireme.node12.modules.Filesystem$FSImpl.runAction(Filesystem.java:184)
    at io.apigee.trireme.node12.modules.Filesystem$FSImpl.stat(Filesystem.java:624)
    at io.apigee.trireme.node12.modules.Filesystem$FSImpl.prototypeCall(Filesystem.java:287)
    at io.apigee.trireme.core.internal.AbstractIdObject.execIdCall(AbstractIdObject.java:189)
    at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:101)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)

Is node_modules's path resolution different between Node and Trireme? And can I resolve file dependencies without changing the files in node_modules?

niso1985 commented 5 years ago

I temporarily use webpack to bundle the JavaScript files. At this time, the following warning will occur.

17:27:10.993 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - open(/Users/ktsujino/projects/myapp/my_js_app/dist/bundle.js, 0, 438)
17:27:10.993 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem - Opening /Users/ktsujino/projects/myapp/my_js_app/dist/bundle.js with [READ]
17:27:10.993 [Trireme Script Thread] DEBUG io.apigee.trireme.kernel.fs.AdvancedFilesystem -   open(/Users/ktsujino/projects/myapp/my_js_app/dist/bundle.js) = 4
17:27:10.996 [Trireme Script Thread] DEBUG io.apigee.trireme.core.internal.ScriptUtils - Executing script from /Users/ktsujino/projects/myapp/my_js_app/dist/bundle.js in interpreted mode because it was too large

Is there a performance impact compared to loading individual files?

typekpb commented 3 years ago

@niso1985 I'm interested in running webjars-packaged node modules with trireme, you seem to have some success in that. Would you mind sharing the sample with me?