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.
Related
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
I've been trying to deploy my nestjs api to azure since yesterday and have not been successful. At first I was trying to push it to a linux cloud service plan and was able to deploy it from vs code, see in the azure logs that the app was successfully started, but it would not return any data from my endpoints and after some digging, I kept seeing some container failures. I tried troubleshooting that for a while then decided I would try setting it up on a windows app service instead.
Following this guide: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-get-started-nodejs, I pushed my nestjs app up to an azure app service on windows and again, it did not work. I pulled down the repo in that article to compare it to mine and they have the entry point in the web.config for the nodejs app pointing to index.js. That index.js doesn't exist in my nestjs app and I did some research and found out that the entry point for a nestjs app after everything is compiled is main.js. There is another difference in that sample project and my nestjs app in that the nestjs app's main.js file appears to be in a dist folder, rather than at the root of the wwwroot path.
My nestjs app obviously didn't contain a web.config out of the box so I created one using the hello world repo's as an example. I updated the iisnode path to dist/main.js and the rewrite path as well to the same path/file since that's the only thing I can think to do.
The only other wildcard is the node version number that I'm changing in azure for the WEBSITE_NODE_DEFAULT_VERSION application setting...I'm not sure what that should be for my nestjs app. My current local version is 12.16.2 but when I change the version to that on azure, it doesn't work.
I'm not sure what else to try here - I'd be fine trying to go back to linux if I could sort out the docker container issue but that seemed like a dead end. I think I'll likely have more luck continuing down the windows route if I can just get this web.config / version thing to work.
Is main.js in the dist folder where I should be pointing my web.config? Is there a max version limit on azure? Is there anything else I might be missing?
EDIT: After turning on streaming logs - I'm now seeing this exception
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:434:25)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object. (D:\Program Files (x86)\iisnode\interceptor.js:459:1)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
after some googling, I've found that exception was common with older versions of node (< 4). I'm well beyond that version and have azure set to a version well beyond that as well.
I got it sorted out with the help of a friend. Running this in the azure cli got things sorted out using the linux setup.
az webapp config set --resource-group myResourceGroup --name myAppServiceName --startup-file "npm run start:prod"
I'm trying to create some cron jobs via the Heroku scheduler plugin. I've tested my node script on my local machine and it works fine, however, when I commit and push to heroku, when I run heroku run node check_work_orders.js, I get this error:
Running node check_work_orders.js on ⬢ fms-sandbox... up, run.4992 (Free)
module.js:471
throw err;
^
Error: Cannot find module '/app/check_work_orders.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:393:7)
at startup (bootstrap_node.js:150:9)
at bootstrap_node.js:508:3
For reference, I was following this guide.
What am I doing wrong here?
Since my node file was location in my app/check_work_orders.js file, I needed to run heroku run node app/check_work_orders.js. This solved my problem. It was just a matter of running node in the correct directory on the Heroku server.
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’ve deployed a small node.js app that runs fine locally in visual studio 2015 to Azure using the Azure publish option (right click – publish – azure profile etc.).
However, when I visit the site all I get on the page is:
The page cannot be displayed because an internal server error has
occurred.
If I connect VS server explorer up to the Azure instance to view the logs, inside logging-errors.txt I can see the following logged lots of times:
Wed Jul 29 2015 12:22:36 GMT+0000 (Coordinated Universal Time): Unaught exception: Error: Cannot find module 'ms'
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> (D:\home\site\wwwroot\node_modules\debug\debug.js:14:20)
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)
This is a brand new web app provisioned via the preview portal.
There is no ‘ms’ package defined either in my project dependencies or in the node_modules folder, so I'm assuming this is a Microsoft/Azure specific package required for hosting on Azure.
Have I missed a step in “preparing” my node app for Azure, or is there some other configuarion step I need to perform?
Thanks
It looks like it's having trouble loading modules. Do you have a package.json file that defines your dependencies? The default deployment script that Azure runs when you deploy your site will look for a package.json and perform an npm install --production. That means it will install everything you've defined as in 'dependencies' but not the packages you've defined as 'devDependencies'.
To debug node apps deployed to Azure that won't startup I do:
Open a Powershell on it's scm (https://.scm.azurewebsites.net/DebugConsole/?shell=powershell)
Check your node is set correctly node --version
Attempt to start it and look at errors node .\server.js (or whatever is specified in your package.json > start script.
It would be nice if you could see such a log for when Azure starts the app. However I have not found it.