Cannot publish Bot to Azure using npm in VS Code - azure

I'm trying to publish my chatbot application to Azure as instructed in the Azure Portal build menu:
Screenshot of instructions
I successfully download the code zip file, and it runs fine in VSCode and the Bot Emulator. However, when I do npm run azure-publish , I get the error npm ERR! missing script: azure-publish. I have not changed any of the build files or the node modules. This exact project runs without an issue in the Azure Online App Editor.
I don't understand where I'm going wrong. Where can I find the script for azure-publish? Is it even possible to publish using npm on VS Code? I've seen examples of publishing using Visual Studio, but haven't come across one with VS Code. Screenshot of directory
Any help or insight is much appreciated.

Resolved!
For anyone who might have the same problem, I had missed adding "scripts": {"azure-publish": "node publish.js"} to my package.json. Online Code Editor doesn't do it for you, so it has to be manually done if downloading code zip file.

Related

How do I run and debug NodeJS projects from Visual Studio through a set of scripts instead of "npm start"?

Using Visual Studio 2019, I have downloaded all the dependencies needed to run NodeJS scripts and all works well. I can only run each .js script from VS (Ctrl+F5), but I want to know whether its possible to run a series of scripts like I would normally do via command prompt using npm start, but in real-time through VS? It's very important to me that I do not modify any script file in order to make this work, but rather let VS do the job instead of npm start, if It's possible at all.
I already have a project setup which I can successfully run via command prompt with npm start, but can I run and debug it with VS?
My main goal is to get any console output and even use breakpoints, aka. properly debug my code.
Actually, in VS IDE, there is a default node js project template that Microsoft provided.
You only have to install the workload Node.js development on the vs_installer so that you can use that template.
I think you should create such project template which follows the rule of VS IDE with node.js. And then migrate your old project's content into this new project.
Note: in this project, there is no such easy way to start several js files at the same time unless you nest nested js methods in the starting js file. And other types of projects do the same.
If you want to debug other js files, you only need to right-click on the file on the Solution Explorer. Every time switch like this, you can debug other js files.
You do not have to use npm start in this way and just click Debug to debug the project.
I am not sure about Visual studio, but you can debug on Visual Studio Code.
you can debug from run menu.

azure functions -running npm install on azure portal

This is a how to question, not a problem
I would like use an npm package in my javascript Azure function. How do I get a console in the azure functions portal to run npm install? If there is a better way to reference the npm package, this will answer my question too. A documentation reference with an example of installing the npm package in an
Azure function would also be appreciated.
I apologize for this basic question. I am new to both node and azure functions and have enjoyed learning what I have so far, but this simple procedure is eluding me.
Thank you for any help you can give me
You can use the KUDU console at https://yourfunctionappname.scm.azurewebsites.net and navigate to the wwwroot folder and install the package that you need!
Here is an article that i wrote to showcase how you can install python packages!
However when you deploy the azure function package.json will have all the dependencies and you dont need to install them separately.
Assume the function name is function677761
Step1. Open the browser and visit the Kudo console.
https://function677761.scm.azurewebsites.net/DebugConsole
Step2. In the toolbar menu select DebugConsole/CMD
Step3. Run the commands:
C:\home>ls
C:\home>cd .\site\wwwroot
C:\home\site\wwwroot>npm i date-and-time
C:\home> ls
Step4. My output is
HttpTrigger1
host.json
node_modules
package-lock.json
package.json
Step5. Now inside the file package.json there is the node.js library date-and-time just installed.
"dependencies": {
"date-and-time": "^2.4.2"
}
Step6. I can read the file package.json from here.
https://portal.azure.com/##myemail345.onmicrosoft.com/resource/subscriptions/3877920b-027777-4513-8777a-ca378888917/resourcegroups/group001/providers/Microsoft.Web/sites/function677761/functionsAppFiles
These values are custom.
Depend by my account.
myemail345
group001
function677761
3877920b-027777-4513-8777a-ca378888917
Source1.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#settings
Section.
Manually install extensions .
Source2.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2-v3-v4-export%2Cv2-v3-v4-done%2Cv2%2Cv2-log-custom-telemetry%2Cv2-accessing-request-and-response%2Cwindows-setting-the-node-version
Section.
Folder structure

TeamCity WindowsAzure.targets causing errors in deployment

We are currently trying to setup an Angular 2 project that also contains a Cloud Service project in its solution. We have set up numerous Angular 1 projects containing Cloud Service projects and have had no errors. When trying to run the MSBuild step for the Angular 2 project, we get the following error on the TeamCity build server:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure Tools\2.7\Microsoft.WindowsAzure.targets(2787, 5): error MSB3021: Unable to copy file "C:\TeamCityBuildAgent\temp\buildTmp\.NETFramework,Version=v4.6.1.AssemblyAttributes.cs" to "C:\SourceControlFolder\Apps\MyApp\MyApp.CloudDeployment\obj\Debug\Website\C:\TeamCityBuildAgent\temp\buildTmp\.NETFramework,Version=v4.6.1.AssemblyAttributes.cs". The given path's format is not supported.
The main problem seems to be the build attempting to throw the full C:\TeamCityBuildAgent.. path into the obj\Debug\Website folder.
My current MSBuild parameters are:
/p:Configuration="Dev"
/p:platform="Any CPU"
/p:OctoPackEnforceAddingFiles=true
/p:OctoPackProjectName=MyApp_Dev
I've tried the following solutions:
Making sure the latest Visual Studio Update is installed (for MSBuild)
Running the install tool to repair Azure Tools 2.7 on the build server.
Changing the debug configuration in the build.
Ensuring TypeScript 1.7.6 is installed on the build server (even though it's an Azure.targets issue) [https://github.com/Microsoft/TypeScript/issues/6215]
Updated the project to Azure Tools 2.9. The same error remains except it's failing on the 2.9 folder instead now.
Curious if anyone else has experienced this error and knows a fix. I'll keep this post updated as I try other solutions.
Update
It appears that what is causing this issue is this line within the .csproj file:
<FilesToIncludeForPublish>AllFilesInProjectFolder</FilesToIncludeForPublish>
This is specified for our build configurations to copy all files generated by the ng build to the output directory of the publish. What I don't understand at the moment is how this works on all of the devs' local machines but does not work on our build server. Will keep this posted as I find more info or any kind of workaround.
This ended up being the fix:
Instead of targeting the .sln in MSBuild, we specifically targeted the .csproj file. This fixed the build errors and allowed us to keep the FilesToIncludeForPublish tag inside.

Issue with Firebase deployment

Obviously I am missing something (!)obvious but I simply cannot deploy my app to firebase. I am following this google guide for progressive web apps. Web server didn't work for me ( to access my app from other devices ), so I tried using firebase as was suggested in the end of the guide. I follow the directions, everything executes with no issues and all I get at the end is "Welcome to Firebase hosting" default message. I am using linux, here is what I did:
Installed firebase tools with "sudo npm install -g firebase-tools"
Went to project root directory and used "firebase init". I selected hosting, typed in "/" as public directory and chose the configure for single page option. Everything worked fine.
Typed "firebase deploy" and again everything completed with no errors. No result.
Tried adding manually all my project files (Firebase dashboard - Storage). Still nothing.
I also read their guide, but didn't find any steps I missed or failed. So what am I doing wrong here?
Thanks

NPM errors and control in Azure Websites

I want to build my Node.JS application in a Azure Website.
There will be an usage of different NPM packages via my packages.json file.
My problem is that I often receive error messages which are related to missing NPM files.
Normally I put my files via FTP or edit them per VS Studio 15 Azure plugin directly on the server. This may be the reason why NPM isn't triggering as Microsoft intended it.
I would prefer a way in which I can just run commands with elevated privileges to have full control over NPM by myself.
Which ways are possible to avaid these problems?
If you're publishing your nodeJS application 'manually' via FTP there are little concerns about that.
First of All, 'manually' means manually.
Git
If you use continuous deployment via Git the final deployment step is to call npm install in your current application folder, this will install all the packages listed in package.json file.
The node_modules folder is excluded by default in .gitignore file, so all packages are downloaded by the server
Web deployment
If you're using web deployment from visual studio or command line, all the files contained by your solution are copied to Hosting environment including node_modules folder , because of this the deployment would take a long time to finish due the huge amount of dependencies and files that the folder contains.
Even worst: this scenario could take you to the same scenario you're facing right now.
FTP deployment
You're copying everything yourself. So the same thing occurs in Web Deployment is happen in FTP deployment method.
--
The thing is that when you copy all those node_modules folder contents you're assuming that those dependencies remains the same in the target enviroment, most of the cases that's true, but not always.
Some dependencies are platform dependent so maybe in you're dev environment a dependency works ok in x86 architectures but what if your target machine or website (or some mix between them) is x64 (real case I already suffer it).
Other related issues could happen. May be your direct dependencies doesn't have the problem but the linked dependencies to them could have it.
So always is strongly recommended to run npm install in your target environment and avoid to copy the dependencies directly from your dev environment.
In that way you need to copy on your target environment the folder structure excluding node_modules folder. And then when files are copied you need to run npm install on the server.
To achieve that you could go to
yoursitename.scm.azurewebsites.net
There you can goto "Debug Console" Tab, then goto this directory D:\home\site\wwwroot> and run
npm install
After that the packages and dependencies are downloaded for the server/website architecture.
Hope this helps.
Azure tweak the Kudu output settings, in local Kudu implementations looks the output is normalized.
A workaround -non perfect- could be this
npm install --dd
Or even more detailed
npm install --ddd
The most related answer from Microsoft itself is this
Using Node.js Modules with Azure applications
Regarding control via a console with elevated privileges there is the way of using the Kudu console. But the error output is quite weird. It's kind of putting blindly commands in the console without much feedback.
Maybe this is a way to go. But I didn't tried this yet.
Regarding deployment it looks like that Azure wants you to prefer Continuous Deployment.
The suggested way is this here.

Resources