Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token import when serving locally #15

Open
jirungaray opened this issue Nov 1, 2017 · 2 comments
Open

SyntaxError: Unexpected token import when serving locally #15

jirungaray opened this issue Nov 1, 2017 · 2 comments

Comments

@jirungaray
Copy link

jirungaray commented Nov 1, 2017

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

@jirungaray jirungaray changed the title File not found when serving locally SyntaxError: Unexpected token import when serving locally Nov 1, 2017
@cmddavid
Copy link

cmddavid commented Nov 5, 2017

Getting the same problem with ngx-translate/core, according to this issue a fix would be to convert the package to es2015 using Babel: ngx-translate/core#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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants