Search code examples
node.jsmoduleinstallationreferenceerror

Installed a module containing a source file, but still getting a reference error


I just installed a package -- https://github.com/ryohey/node-stratum-client using

npm install node-stratum-client

Although I can see this file installed

./node_modules/node-stratum-client/src/StratumClient.ts

when I attempt to run a node script containing these lines

require("node-stratum-client")
const client = new StratumClient()

I get an error

/Users/satishp/Documents/workspace/run.js:3
const client = new StratumClient()
               ^

ReferenceError: StratumClient is not defined
    at Object.<anonymous> (/Users/satishp/Documents/workspace/run.js:3:16)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:617:3

I'm using npm v 5.6.0. What file do I need to be installed so taht my node script will recognize the module I have installed?


Solution

  • You need to store the required module in a variable:

    const StratumClient = require('node-stratum-client')
    const client = new StratumClient()