So, I'm trying to create my first microservice using NestJS, but the moment I try to run it, the service stops with this error:
[13:39:21] Found 0 errors. Watching for file changes.
Error: Cannot find module 'C:\Users\voryi\IdeaProjects\YWA\des_server\services\learning-service\dist\main'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
there's no main.js file in the first level of your dist directory. You can define the entry file by adding this to your nest-cli.json:
"entryFile": "learning-service/src/main"
the default is main
try npm run build and then restart your service
I use monorepo setup and this issue happens whenever I start the nestjs server from non-root folder by mistake.
Usually, removing the dist folder and restarting the nestjs server works for me.
In my case, the main.js file was inside src folder so I had to change the script to:
"start:prod": "node dist/src/main"
maybe simply use this inside the project,
npm i #nestjs/microservices
Related
Just opened my IDE for my project on react and this weird stubborn error popped up on my nodemon server.
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module 'C:\Users\Hammad\ngo_project\index.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...
I tried deleting and reinstalling node_modules folder and even package_lock but still the same error is popping.
You will execute the node index.js command
Want to launch a file with the name index.js
You are in the folder of your project, you have this path: C:\Users\Hammad\ngo_project
Your file is not in this folder, maybe you have a folder called "js" or some other name that contains your index.js file.
When you launch the node index.js command.
Node Js is looking for your file in the project C:\Users\Hammad\ngo_project Node Js does not go to other subcathologists, therefore it does not find your index.js file.
You need to move the index.js file to your ngo_project folder.
After that, repeat the launch of the node index.js command.
Also important!
If you have "type": "module" in package.json
You need to use in your index.js connection like this: example import fetch from 'node-fetch';
If "type": "CommonJS" is specified in the package.json file or not specified at all.
You need to use in your index.js connection like this: example const fetch = require('node-fetch');
Good luck!
Try use Yarn, not npm. I use Yarn and it help me.
Delete node_modules and package-lock.json, after that in terminal write yarn install
I am receiving the following error after running npm start:
Error: Cannot find module '../build/jvm_dll_path.json'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/stature-gqdss/node_modules/java/lib
[nodemon] app crashed - waiting for file changes before starting...
Can you help me with this issue?
First, you should check if the server is already running and kill the existing server. If no other server is running, try reinstalling your dependencies and try again.
npm install
I have a hack here. You can simply create a file named jvm_dll_path.json inside node_modules\java\build and paste the path of server to this, between quotes like shown below..
";C:\\Program Files\\Java\\jdkX.X.X_XXX\\jre\\bin\\server"
For me running
node postInstall.js
in the node_modules/java folder worked.
I was trying to run this command from my user directory
NODE_ENV=~/Public/project node socket.js
But it return this error
Error: Cannot find module '/home/user/socket.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
The thing is i do not want to change directory. Is it possible to do that? And why this is happening?
NODE_ENV is, by convention, the type of environment you're running in, e.g. Development or Production or Test. It only matters for modules that inspect it and set options accordingly, e.g. Many loggers will default to more verbose in development.
Not really sure why you wouldn't just change directories, but your call to server.js can be an absolute or relative path. If the file is in the /home/user/project folder, you can (from /home/User) just call
node ./project/socket.js
After a little mor research, i found this
And according to that site, i have to do this
export NODE_CONFIG_DIR=/home/user/Public/project/config
and run this
node ./Public/smart-backwall-server/socket.js
I didn't close my mongod when closing the laptop and now its giving me an error. On top of that, I delete the mongod data directory with all my data in it. Now I can start up my apps using node js - is there anyway to fix this or do I need to redo all my app.js again?
Error: Cannot find module '/home/ubuntu/workspace/RESTful/RESTful
Routing/RESTfulBlogApp/cats.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
All the files which are required in your node app must be present at the time of execution.
As per the error, it is unable to find cat.js in the required folder. You need to create again all the required files, and if they were your dbSchema, i would suggest you create your schemas again before running the app.
I'm trying to deploy a node app onto the Cloudbees ClickStart.
I've create a node js ClickStart (this creates the jenkins job, git repository and application container).
Zipped up my app, then deployed using the Cloudbees SDK.
bees app:deploy -t nodejs -a nodeshort -v nodeshort.zip
When I try to access the URL the application is deployed on I get a 502 Bad Gateway.
Checking the application logs, I see the following printed multiple times:
module.js:340
throw err;
^
Error: Cannot find module '/mnt/e1/genapp-apps/660f9784/main.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
What has caused this? More importantly, what can I do to resolve it? I've tried trashing the clickstart and recreating, but I get the same outcome each time.
Thanks
The way in which you zip the file is important.
zip -r ../myapp.zip * => WORKS FINE
zip -r myapp.zip myapp/* => DOES NOT WORK
nodejs stack expect a "main.js" script to be present in application rootdir.
You have this nodejs ClickStart working. Maybe you should compare your code with the ClickStart.