2

I'm facing the following error message on Windows 10x64 for Java module while executing javascript code:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'java'
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
        at Function.Module._load (internal/modules/cjs/loader.js:562:25)
        at Module.require (internal/modules/cjs/loader.js:692:17)
        at require (internal/modules/cjs/helpers.js:25:18)
        at Object.<anonymous> (C:\Users\Rau\Desktop\Test.js:1:12)
        at Module._compile (internal/modules/cjs/loader.js:778:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
        at Module.load (internal/modules/cjs/loader.js:653:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        at Function.Module._load (internal/modules/cjs/loader.js:585:3)"

var java = require('java');

var javaLangSystem = java.import('java.lang.System');
1
  • you should do npm i java -S in your project folder Commented Oct 3, 2019 at 20:04

1 Answer 1

1

The java module is not automatically available (i.e. it is not included with node.js ). It is available through the npm registry: https://www.npmjs.com/package/java

What this error is trying to tell you is it looked in all the paths for the java module and could not find it.

Make sure you have the java module installed via:

npm install java
Sign up to request clarification or add additional context in comments.

1 Comment

I tried following command npm install java -g npm list java ==> Output => <drive>:\nodejs `-- [email protected] However when I tried to import java it says cannot find module 'java'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.