I have a Node.JS application that I want to deploy on AppEngine. At the moment I am getting following error:
Beginning deployment of service [default]...
Building and pushing image for service [default]
ERROR: node.js checker: Neither "start" in the "scripts" section of "package.json" nor the "server.js" file were found.
ERROR: (gcloud.app.deploy) Your application does not satisfy all of the requirements for a runtime of type [nodejs]. Please correct the errors and try again.
This makes sense as this is the folder structure:
client
server
main.js
app.yaml
As you can see I have a separate folder for my client code and server code.
If I put the app.yaml file inside the server folder, the deployment works but when I try to access the app it cannot find the client files as they were not part of the deployment.
Is there anyway to configure this in the app.yaml or do I need to refactor my app?
actually app engine required package.json in your root directory ... and in which put script of start.. like start:node server/main.js
Related
I have a yml file setup with Github actions while it deploys Azure doesn't actually serve the site correctly. It states in the Azure documentation that the container will start with one of the common files:
bin/www
server.js
app.js
index.js
hostingstart.js
My folder structure looks like this:
dist
server.js
...
build
...
node_modules
...
If I move /dist into the root the express server initiates and begins trying to serve routes but blows up due to the folder structure. Any help is appreciated.
You have to modify server.js file. You can find it following this path:
Configuration
General Settings
Startup Command
Type "./dist/server.js"
Do you have a Startup Command set within the Configuration -> General Settings page ?
If not, you can use this to provide optional command(s) to control how your instance starts.
You use this when you deviate from the standard its expecting.
really hoping someone can point me in the right direction with this one as i'm having no luck at all. I'm trying to host a simple nodejs sveltekit application on a Windows based azure app service, but cannot get the application to start / run.
I'm using the adapter-node adapter for sveltekit to generate the build output as a self contained node app. After sveltekit generates the build output I inject a simple package.json file to the root of the build folder to instruct node to use the ESM style imports which simply contains a single property of type="module".
package.json
{
"type": "module"
}
Lastly I also inject a web.config into the root of the build folder for use with IISNode. The web.config file used is the same as from the nodejs quickstart guide provided by MS. The web.config can be seen here.
The final folder structure of the build output is simply:
build
└───assets
│ └───_app
│ │ ...
└───prerendered
│ index.js
│ package.json
│ web.config
Locally I can take this build folder, place it anywhere on my machine and it runs perfectly by simply running:
node index.js
The Problem
Even though it works perfectly locally, when I deploy the application to the Azure app service the application will not start with the browser simply displaying "This page isn’t working right now".
When I check the logs I see the following error:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: D:\home\site\wwwroot\index.js
require() of ES modules is not supported.
require() of D:\home\site\wwwroot\index.js from D:\Program Files (x86)\iisnode\interceptor.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from D:\home\site\wwwroot\package.json.
The error tells me that MS's iisnode\interceptor.js is using the commonjs style require syntax and cannot import the ES module of my index.js.
I found someone having a similar problem and a suggested solution here. The suggested solution is to create a new file next to my index.js file and configuring it as the app service's (or more specifically iisnode's) entry point in the web.config. The new file would be named run.cjs and only contain the following:
import("./index.js");
I tried this option, adding the new run.cjs file and updating the web.config to set this as IISNodes entry point:
<add name="iisnode" path="run.cjs" verb="*" modules="iisnode"/>
When I try the site after doing this I get a new problem. The site now loads but instead of seeing the app, the js from index.js renders as raw text into the browser.
The azure app service WEBSITE_NODE_DEFAULT_VERSION is set to ~14 and I can see from Kudu that the version running is 14.16.0 - my local machine is 14.17.0 so the node version looks to be ok.
Can anyone help??
Thanks in advance
Please re-install/update the npm module on your project.
Make sure all these files are present in your project.
Do not import your index.js file in other files like run.cjs or run.mjs, after building your application in your local and publish it in azure app service.
{
"type": "module"
}
This above code is required in the package.json file.
Check your npm reference files, if anyone of them is not installed properly, then you'll get the raw data which is present in app,js file, as output
I am new to google cloud and so I deployed a Nodejs app using the tutorial. Everything worked just fine, here is my file structure (I didn't make the my-nodejs-service folder):
app.yaml
server.js
package.json
I deployed it, everything was fine. So then I tried to make it look like this:
mySite/
server.js
package.json
app.yaml
public/
site contents
I just forked a github repo, deployed it, and it didn't work. By that I mean the site didn't load! I checked the logs, and here was what appeared:
Error: Cannot find module '/workspace/server.js'
at Function.Module._resolveFilename (loader.js:880)
at Function.Module._load (loader.js:725)
at Function.executeUserEntryPoint (internal/modules/run_main.js:72)
"GET / HTTP/1.1" 500
listening on port 3000
It said it couldn't find the server.js file. Was it because I moved the code into the folder? I deployed it on the current working directory being the folder mySite.
package.json (Im only including the scripts part, it other stuff such as the dependencies):
{
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
}
}
Other things I tried:
deploying with app.yaml at the end of the deployment command
Using path.join()
Deploying multiple times
Other info:
I checked the logs and I got this:
"GET / HTTP/1.1" 500 - - "Web browser agent info in here"
Another showed:
i This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
And another log said:
!! Process was terminated because the request deadline was exceeded. Please ensure that your HTTP server is listening for requests on 0.0.0.0 and on the PORT environment variable. (Error code 123)
App Engine uses a set of conventions in order to be able to deploy and run code successfully. As you've seen, you can't necessarily take an arbitrary web server solution and deploy it successfully.
Please include more details about specific steps you take. For example, you say "I .. deployed it". It would be useful for you to include the command that you used and any immediate errors that were thrown to provide readers with more context when helping answer your question. It's unclear to me from which directory you attempted to deploy the mySite example but I assume from within mySite.
The first error Cannot find module '/workspace/server.js' results because App Engine builds your code using Cloud Build and Cloud Build (by default) puts your code into a /workspace directory on the build VM. It's not very user-friendly, but it was unable to find server.js and, because your package.json specifies node server.js, it needs it.
Another statement that gives me pause is listening on port 3000. I'm not very familiar with the Node.JS runtime but generally App Engine expects web server's to either listen on port :8080 or provide an environment variable that specifies the port, In your tutorial, this is explained: "process.env.PORT is not set, port 8080". That's probably (!?) another issue.
Lastly, you may (I think you probably don't) need to explicitly reference the public subdirectory (unsure) in order to ensure that it's available at runtime.
I am getting an error in the screen shot bellow deploying a node.js app on heroku saying that the buildpack was unable to detect a node.js codebase
I set the build pack, the package.json is at the root level as is the app.js file
https://www.dropbox.com/s/y1bg6eir2w93m8a/Screenshot%202020-05-29%2013.44.36.png?dl=0
Not sure what I am doing wrong - thanks!!
The error is clear:
A Node.js app on Heroku requires a package.json.
In the files listed below, you can see that the package.json file is missing. You have to commit it and repush your code to Heroku.
I am trying to deploy an angular2(sample app created from command "ng new my-app" ) app to GitHub using angular-cli-ghpages as mentioned in
http://crookedcode.com/2017/02/24/deployment-of-angular2-app-to-github-pages/
But whenever I am executing the command I getting error as below,
After searching on Google, I could see suggestion that it might be issue with node. But I am not clear about what needs to done to fix this.
my node version is v9.2.0
npm version is 5.5.1
Please help.
You Can follow these steps to deploy the files to gh-pages
Angular 2 Deployment in Github Pages
Testing Deployment of Angular2 Webpack in ghpages
First get all relevant the files from the Dist Folder of your application
for me it was the css files in the assets folder main.bundle.js polyfills.bundle.js vendor.bundle.js
Then push this files in the repo which you have created.
1 -- If you want the application to run on the root directory - create a special repo with the name [yourgithubusername].github.io and push these files in the master branch
2 -- Where as if you want to create these page in the sub directory of in a different brach other than that of the root , create a branch gh-pages and push these files in that branch.
In both the cases the way we access these deployed pages will be different .
For the First Case it will be https://[yourgithubusername].github.io and for the second case it will be [yourgithubusername].github.io/[Repo name].
If Suppose you want to deploy it using the second case make sure to change the base url pf the index.html file in the dist as all the route mappings depend on the path you give and it should be set to [/branchname].
Link to this page