简体   繁体   中英

For node v 4.4.2 on Linux, getting “Error: Cannot find module './namegen.js'”

I'm using Node v 4.4.2 on the following version of Linux

[davea@mydevbox mydir]$ uname -a
Linux mydevbox.mydomain.com 1.1.2-45.38.amzn1.x86_64 #1 SMP Wed Mar 16 17:15:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I installed my version of node from a tarball. I'm getting this error when I run my script

[davea@mydevbox mydir]$ node myscript.js 
Validation Complete
module.js:327
    throw err;
    ^

Error: Cannot find module './namegen.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/davea/Automate-04-01-2016/js/Optimus.js:6:10)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)

I'm confused as to what this means but even more confused as to what I need to do to solve it. Advice is appreciated, - Dave

I tried installing the module using the method you suggested, but got the same error. 我尝试使用您建议的方法安装模块,但出现相同的错误。 See the output from installing and re-running my script

[davea@mydevbox ~]$ npm install namegen
namegen@0.0.0 node_modules/namegen
[davea@mydevbox ~]$ 
[davea@mydevbox ~]$ cd mydir
[davea@mydevbox mydir]$ node myscript.js 
Validation Complete
module.js:327
    throw err;
    ^

Error: Cannot find module './namegen.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/davea/mydir/js/Optimus.js:6:10)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)

Did you check your node_modules for the namegen module? It is created with this directory name. Also looking up https://www.npmjs.com/package/namegen , this module has no documentation and the provided github link for source is broken.

You will have to install this module manually to fix this error:

npm install namegen

Add a -D flag if you want to add this as devDependency.

What the error means is that somewhere in your code your had a line require('namegen') and the "namegen "module is not found as part of your dependencies.

After doing the install, start node your working directory where your package.json is there. Run the code below in REPL mode:

require('namegen').toString();

You should see the code of namegen package that you want to use.

If you refer to the package using require('./namegen') that will not work. You should change it to require('namegen') .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM