davideast / angular-universal-express-firebase

A packaged Cloud Function to serve Angular Universal apps.
50 stars 9 forks source link

SyntaxError: Unexpected token import when serving locally #15

Open jirungaray opened 6 years ago

jirungaray commented 6 years ago

I've completed the setup and tried running the SSR locally, unfortunately whenever i try to hit localhost:5000 i get an error on the Firebase function:

SyntaxError: Unexpected token import

Which from I can gather from my research is related to Node.js not supporting modern versions of ES and can be solved by includingvar express = require("express"); Unfortunately that doesn't seem to fix the issue.

The log is as follows:

=== Serving from ''...

i functions: Preparing to emulate functions. Warning: You're using Node.js v8.9.0 but Google Cloud Functions only supports v6.11.1. i hosting: Serving hosting files from: dist ✔ hosting: Local server: http://localhost:5000

✔ functions: trigger: http://localhost:5001/curselo-web/us-central1/trigger [hosting] Rewriting / to local function trigger info: User function triggered, starting execution error: /functions/node_modules/@angular-mdl/core/components/button/mdl-button.component.js:11 import { Component, Input, ElementRef, Renderer2, NgModule, ViewEncapsulation } from '@angular/core'; ^^^^^^

SyntaxError: Unexpected token import at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:599:28) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3) at Module.require (module.js:579:17) at require (internal/module.js:11:18) at Object.jriz (/functions/dist-server/main.bundle.js:1:707107) info: Execution took 82 ms, finished with status: 'crash' 127.0.0.1 - - [01/Nov/2017:15:31:55 +0000] "GET / HTTP/1.1" 500 99 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" error: Function worker crashed with exit code: 1

cmddavid commented 6 years ago

Getting the same problem with ngx-translate/core, according to this issue a fix would be to convert the package to es2015 using Babel: https://github.com/ngx-translate/core/issues/581

After using babel to convert the module to es2015 I tried to serve the application via "firebase serve --only functions,hosting". Although the error went gone a new error pops up without any useful info: Failed to emulate ssrapp

It is worth mentioning the same application does run via SSR via the built in Angular Universal Starter command: "npm run serve:ssr". So something strange seems to be going on.

jirungaray commented 6 years ago

I did some research and indeed the issue is because of node not supporting ES6, I re transpiled some libs and got it to go away. Unfortunately some other libs started failing because they are not SSR compatible. At this point i'm trying some final hacks before dropping angular, to be honest it doesn't seem to be production ready.