deanmau5
deanmau5

Reputation: 871

Node not loading module from project root

I'm beginning some learning projects in node and am having problems with node finding installed modules.

I installed a module into the root directory of a project, which looks like the following:

C:\Users\Dean\Documents\NodeProjects\ReadWords

which has my node_modules folder and readwords.js file I would be running to call the module.

Within node_modules is censorify-deanmau5 folder and in there, my various module files.

readwords.js has on line 1

var censorify = require('censorify-deanmau5');

and in the console when I try to run the file, I get the following:

C:\Users\Dean\Documents\NodeProjects\ReadWords>node readwords.js

module.js:340
  throw err;
      ^
Error: Cannot find module 'censorify-deanmau5'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Dean\Documents\NodeProjects\ReadWords\readwo
rds.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

Surely this should be working with having node_modules in the same directory as the .js file I'm trying to run? Am I missing something here?

Upvotes: 0

Views: 548

Answers (1)

Your package seems to have invalid main entry point. Either rename censorify.js as index.js or add "main": "./censorify.js" to package.json.

Upvotes: 1

Related Questions