I have bot in Discord Bot Maker. Its working perfectly on my pc (Windows 10), but when I move it to my VPS (Ubuntu 16.04) and try to start it using node bot.js, I will get error with missing module.
Error:
module.js:550
throw err;
^
Error: Cannot find module './constants'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/justwolf/butter/node_modules/ws/lib/websocket.js:19:19)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
bot.js: https://hastebin.com/koredupoka.js
The error :
Error: Cannot find module './constants'
means that somewhere in your code you have
.... = require('./constants')
but the file constants.js doesn't exist or at least not where it's supposed to be. Maybe when you uploaded your bot script to your VPS you forgot to upload that file.
Sometimes, in ready-made scripts, configuration variables such as database credentials and stuff are stored in a file named constants.js and this file is not versionned (it has en entry in .gitignore). Maybe you have a file named constants.js.dist or constants.js.example. It means you need to edit it and rename it to constants.js
Related
After installing express-gateway, when I create API gateway using following command,
eg gateway create
I am getting following error.
[EG:config] error: Cannot find module 'C:\My Content\Microservice Projects\FIFA Team Selection\config\models\users.json'
C:\My Content\Microservice Projects\FIFA Team Selection\node_modules\express-gateway\lib\config\index.js:15
throw err;
^
Error: Cannot find module 'C:\My Content\Microservice Projects\FIFA Team Selection\config\models\users.json'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at forEach.model (C:\My Content\Microservice Projects\FIFA Team Selection\node_modules\express-gateway\lib\config\config.js:68:27)
at Array.forEach (<anonymous>)
at Config.loadModels (C:\My Content\Microservice Projects\FIFA Team Selection\node_modules\express-gateway\lib\config\config.js:65:61)
at Object.<anonymous> (C:\My Content\Microservice Projects\FIFA Team Selection\node_modules\express-gateway\lib\config\index.js:11:10)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
child_process.js:624
throw err;
^
Error: Command failed: C:\My Content\Microservice Projects\FIFA Team Selection\node_modules\.bin\eg.cmd gateway create
at checkExecSyncError (child_process.js:601:13)
at execFileSync (child_process.js:621:13)
at exports.executeInScope.env (C:\Users\bmaheshwari\AppData\Roaming\npm\node_modules\express-gateway\bin\execution-scope.js:37:5)
at Object.exports.bootstrap (C:\Users\bmaheshwari\AppData\Roaming\npm\node_modules\express-gateway\bin\environment.js:11:7)
at Object.<anonymous> (C:\Users\bmaheshwari\AppData\Roaming\npm\node_modules\express-gateway\bin\index.js:9:46)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
I tried removing node_modules folder and re-installing it again, but issue persists.
This can usually happen when something is wrong during the scaffolding/creation section. I can also see you're running the command from Windows.
We had different users complaining about some weird CLI problems with that operating system which I'm not actively supporting right now.
It shouldn't be too hard to copy that file from the repository and place it in the right directory. I know it's a workaround, but it should do the trick.
With the package.json, it's possible to do something like this
"dependencies": {
"WindowManager": "./lib/WindowManager"
},
But when trying to do this in Electron, it gives me this error:
App threw an error during load
Error: Cannot find module 'WindowManager'
at Module._resolveFilename (module.js:470:15)
at Function.Module._resolveFilename (.../desktop/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (.../desktop/lib/init.js:15:35)
at Object.<anonymous> (.../desktop/lib/init.js:22:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
Is it because of Electron, or am I doing something wrong?
./lib/WindowManager is a folder with a package.json in it with a main pointing to the WindowManager.js, so that should work.
The case you try to do normally works, make sure that the dependency "WindowManager" has been properly copied by the build tools to either:
.../desktop/node_modules/electron/dist/Electron.app/Contents/Resources/app.asar/node_modules
or
.../desktop/node_modules/electron/dist/Electron.app/Contents/Resources/node_modules
If WindowManager does not exist in the disted node_modules there is something wrong with your build process, hard to be more precise than that.
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.
I've following folder structure.
I am trying to access my custom module (core_programming/Constants.js) in other files.
I can access it in routes/index.js without any issue using following code.
var Constants = require('../core_programming/Constants.js');
But I am getting error when I try to access it inside core_programming/User.js with following statement.
var Constants = require('Constants.js');
It gives following error:
module.js:338
throw err;
^
Error: Cannot find module 'Constants.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (D:\nodeJsProjects\AutomateBuild\core_programming\User.js:3:18)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
1 Oct 11:56:35 - [nodemon] app crashed - waiting for file changes before starting...
I've tried different ways for defining path in require like ../core_programming/Constants.js and ./core_programming/Constants.js but nothing works out.
What is the correct way for loading custom modules from the same directory.
And, I am on Windows if that helps.
Try to use:
var Constants = require('./Constants.js');
This will force Node to figure out you are looking for a relative path and not a package in node_modules.
On a side note, windows paths use \, so consider trying it as well:
var Constants = require('.\Constants.js');
module.js:340
throw err;
^
Error: Cannot find module './models/todo'
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\Basel\Desktop\Todo List\routes\api.js:1:74)
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 Module.require (module.js:364:17)
C:\Users\Basel\Desktop\Todo List>
Why this application won't start up? I've already tried a global npm install.
In ./models/todo, the period indicates that node will look in the same folder that api.js is in, which would look for \Todo List\routes\models\todo.js. This does not start from the root of the application. To require this, you'll need to us two periods to jump up a level, and specify the app path as well:
var todo = require('../app/models/todo');
maybe you did not set the system value : NODE_PATH; it should point to your global module location;
in Linux: export NODE_PATH=/usr/local/lib/node_modules/ works good for me;
in my case, the file name i had given in my require statement was wrong. I had my models file named posts.js and i was using require('./models/post'). It worked after i changed it to require ('.models/posts')