Home > other >  Angular 12 Universal on Google App Engine error: ./my-app/server/main.js: Syntax error: "("
Angular 12 Universal on Google App Engine error: ./my-app/server/main.js: Syntax error: "("

Time:09-28

I have an Angular 12 app that I converted to Universal.
After shmoozing it a bit it works locally as expected.
I deployed to Google AppEngine but get '500 Error: Server Error'.
Looking at the logs I see the error:
./my-app/server/main.js: Syntax error: "(" unexpected.

My app.yaml is simply:
runtime: nodejs14
entrypoint: ./my-app/server/main.js

I tried building with and without --prod but I still get the same error.
Any help will be appreciated...

Update:
When removing the entrypoint from app.yaml I get the error:

Error: Cannot find module '/workspace/server.js' at 
Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15) at 
Function.Module._load (internal/modules/cjs/loader.js

Here is the scripts section of package.json:

{  
  "name": "my-app",  
  "version": "1.0.0",  
  "scripts":   
{  
    "ng": "ng",  
    "start": "ng serve",  
    "build": "ng build",  
    "prod-build": "ng build --prod",  
    "test": "ng test",  
    "lint": "ng lint",  
    "e2e": "ng e2e",  
    "dev:ssr": "ng run my-app:serve-ssr",  
    "serve:ssr": "node dist/my-app/server/main.js",  
    "build:ssr": "ng build && ng run my-app:server",  
    "prerender": "ng run my-app:prerender"  
  },  
...

CodePudding user response:

Finally solved it (following a discussion with good folk at Angular.io):
It works as advertised if I change app.yaml to the following:

runtime: nodejs14
entrypoint: node dist/my-app/server/main.js

The folder structure is exactly what you get from the universal code generator:
{your project}
  dist
    my-app
      browser
        ... Regular Angular site files ...
      server
        main.js
        ...

In AppEngine the structure you want to upload and sync to your project is:
{your project}
  app.yaml
  dist

  • Related