Npx fails on Azure App Service deployment - node.js

I'm trying to deploy a Node.js (Remix) application to an Azure App Service instance. After installing the npm packages, the post-install script must run for the Remix app to eventually work. The post-install script is npx remix setup node.
Unfortunately, the deployment fails because of the following reason:
npm ERR! could not determine executable to run
I get the same error when trying to use other npx commands, as npx prisma generate. I tried npm exec as well instead of npx.
Thank you in advance!

In startup command try using npx serve -s build/
Also, under your app service Settings blade check all the general settings.
Make sure that your web.config was published along with your app.

Related

Strapi: Warning an error occurred while requesting the API

I've been struggling for hours trying to install Strapi on my Ubuntu server.
Ubuntu: 20.04
nodejs: v14.19.0
npm: 6.14.16
strapi: 4
npx create-strapi-app#latest my-project --quickinstall
All the installation process goes seamlessly but when I go to http://mydomain:1337/admin in order to create a first user I get this warning:
an error occurred while requesting the API.
I know this problem has been encountered several times but none of the suggested solutions have helped me so far.
I also found this error in the Chrome console but I'm not not sure it's related to the my problem:
main.815f1087.js:2 Refused to connect to
'http://localhost:1337/admin/project-type' because it violates the
following Content Security Policy directive: "connect-src 'self'
https:".
Any idea ?
You need to build the app. Read this github issue
Run: npm run build or yarn build or strapi build depending on what you are using
First Build your Application by using npm run build then run npm start.
If you are running strapi CMS on docker, and using docker composer to build, then maintain the default port 1337 when binding the container port to your system port.
Do this: -1337:1337
Not this: -8000:13337
I had this error after upgrading to latest Strapi and all dependencies, what helped me, is to rebuild the Strapi admin interface:
yarn build
or
npm run build
then start develop
yarn develop
or
npm run develop
Got the same problem, a simple restart of the server did it for me.
First of all, need to Build the admin panel and then Start the application.
To build the admin panel,
npm run build
# or
yarn build
To start the application with auto-reload,
npm run develop
# or
yarn develop
when you change the port of your strapi app, you must run npm run build or yarn build or strapi build. because strapi admin templates use default port 1337 and for using on another port you must build the project again.
What I did is to change the host address from 0.0.0.0 to 127.0.0.1 in server.js and then ran npm run build and that fixed my issue. I know it sounds strange but it worked.
Thanks.

Missing files in .bin folder when deploying Node App to Azure App Service

So I was trying to deploy my react app to an Azure Web App.
I used a Github Action to build and install the App and then ZIP Deploy it to Azure.
The Problem is that once I open up the WebApp Page it shows me an Application Error (react-scripts could not be found).
I found out that once I copy the react-scripts.cmd / ps1 (from local /node_modules/.bin) to the node_modules/.bin folder of the webapp "https://{WEBAPP-NAME}.scm.azurewebsites.net" it works.
Unfortunately I would have to do that after every build.
How can I come up with a solution to this error?
What I already tried:
Update node and npm
Remove package-lock
Thanks in advance
Max
My package.json:
It looks like this issue: npm package.json scripts not being called
Try running npm run-script if you want to execute a script that is not executed by a built-in npm command.
So I found out, that react-scripts is only working in dev environments. But Azure uses a production env. Therefore the github action not only has to install the prod node_modules (npm install) but also the dev modules (npm install --only=dev).
Reference:
https://github.com/mars/create-react-app-buildpack/issues/32#issuecomment-276081892

How to deploy Nestjs App (on Azure)?

I am trying to deploy a Nestjs API (with Auth0 authentication). When I run it in VS Code with npm run start:watch server, everything's fine.
Now the question is: what should I do to deploy it on a webserver? Should I only copy the dist folder (after runnin tsc)? what about node_modules? Should I leave the port to 3000?
As a side note I am trying to deploy it on Azure but I guess the questions holds for any platform.
Many thanks!
Modify your package.json file, and add a postinstall script, this script should be tsc or tsc --sourceMap false if you would like to avoid sourceMaps from being generated.
That would make azure to run tsc after installing all npm packages, remember to change start script also, so its value is 'node dist/index.js'

How to run npm command on azure app service after deployment success by VSTS?

Now I can deploy from VSTS to azure, but I can't run npm after deploy is successful.
Now it is work like -> run npm install for branch files => zip => copy to azure => deploy.
I want to add npm run custom-comand to end of this chain.
How to do it?
The Azure App Service Deployment task in VSTS now supports a post-deployment script. Here is a screen-shot from version 3.* of the task:
See Task Parameters for more details.
Windows App Services users: Watch out for an npm bug that prevents multiple npm commands from being run (inline or in a script). For example:
npm install
npm test
Will only run npm install. There are several workarounds including this:
npm install & npm test
There is no out of box build task to achieve the feature you want. If you do want to run the npm from Azure App Service:
Manually: You can go to Kudu console of the App Service and run npm command there:
Automatically: You need to create your own build task to run the npm command via Kudu Rest API
You can run commands like npm install via the Kudu REST API.
Here's a scripted example written in PowerShell.
Add a PowerShell script task after the Azure App Service Deploy task to invoke npm install (or any other command that Kudu supports). And disable the npm install task in your build pipeline.
The Kudu deployment engine that App Service leverages has the ability to run custom deployment scripts. You can include your desired npm command inside of a custom deployment script that will be executed as part of the deployment on Azure's side. No REST API calls required and everything stays in your source control system.
You can use PowerShell task or npm task to execute npm commands .
One thing to note: you also need to upload the .npmrc with auth token to Azure.

How to run a npm script on a deployed Heroku NodeJS app

Under scripts in package.json I have the following.
'refresh': node refresh db
Is there a way to trigger this particular npm script on a NodeJS app deployed on Heroku.
Yes:
$ heroku run npm run refresh
Per the Heroku Node.js Documentation, you can add pre and post install scripts. In addition, you can add scripts that can be triggered by environment variables.
You can also do this using only the browser; Just log in to manage your app in the heroku dashboard (https://dashboard.heroku.com/apps/[app_name]) and there click on the right side of it:
More > Run console
Then you can run any command:
command line in heroku
https://devcenter.heroku.com/changelog-items/1137

Resources