问题描述:

I was just sent the files for a Node.js app (which is working without issues online) and I'm trying to set it up on my Windows machine.

I have Node server running, but I'm stuck trying to actually load the app. I can navigate to the directory with the Node command prompt, and there's an app.js (plus folders like config, components etc) in there which I've been trying to run, but I am getting the following error:

D:\my-directory\game-master>node app.js

module.js:327

throw err;

^

Error: Cannot find module 'config'

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> (D:\posao\aktivni projekti\smart rebellion\game-master

\app.js:7: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 Function.Module.runMain (module.js:441:10)

The thing is, there is no file titled module.js in the directory. I presume it's a built in Node.js file, but then how do I troubleshoot this?

My best reading of the error is that there should be a config.js file somewhere, but that doesn't make sense because these same exact files work with no hickups on a remote server.

网友答案:

If you want to require('./config'), where config is a directory, the file ./config/index.js should exist.

You can't require('config') however, because node.js will try to find it in node_modules.

Check out node.js modules documentation where the require algorithm is well explained.

相关阅读:
Top