-
Notifications
You must be signed in to change notification settings - Fork 2.2k
"Unexpected token import" with angularfire2 on angular-cli, AOT, SSR, and firebase-functions #1073
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
Comments
@sdebaun I recently ran into this myself. I have a fix in the works but I just moved halfway across the country so my schedule is pretty jammed right now. I do expect to get something out next week. There's a big overhaul needed in how we package these modules. We need a UMD bundle for each feature (auth, db) rather than one larger one. I'm looking into mimicking the structure that the main Angular repo uses with their package.json and tsconfig.files. A good example is with the HTTP module. |
@davideast thankyouthankyouthankyouthankyouthankyouthankyouthankyou! I was so excited that I got a client/server monorepo working with SSR, and then wanted to cry when I found out angularfire didn't play nicely. So I should just hold off for a bit, eventually angularfire will work with ssr? YOURETHEBEST!!! |
I've just run into this too trying out universal build with angular-cli, so would love to know what your work around was. I was going to try to build targeting commonjs and pull in to packages.json direct from my own branch. Alternatively I was thinking about swapping out for the firebase admin sdk using Both seemed horrid options atm, the later in particular. I haven't tried either yet. I'll keep my fingers crossed, in the mean time I will continue to play if I get the chance. |
@justingrayston @sdebaun I'm close to a |
@davideast when can we expect this release. I am using "angularfire2": "^4.0.0-rc.1" with "firebase": "^4.2.0" . AOT with angular cli . I am getting the same issue. E:\Angular\designcourse\angular-seo\node_modules\angularfire2\app\firebase.app.module.js:1 Waiting eagerly for your positive response and next release as well. :) |
@justingrayston my workaround was... disable SSR until the fix is posted :) |
@davideast , does rc2 fixes this issue ? |
@sdebaun @justingrayston @KrGyan
Yes and no. Mostly no. #1088 fixed the problem that @sdebaun ran into. The Angular Compiler used deep imports to import the feature modules, when I needed to use the UMD bundle. I spent a lot of time getting the packaging of each module correct. Now, if you use AngularFire2 with Angular Universal, there will be no errors*. However, the data will not render on the server. You'll get back *i think |
@davideast when you say that you intend to wrap the calls, how do you plan on doing so? I imagine there is the possibility to wrap the socket connection into an RxJS websocket but I imagine that would require a lot of work and wouldn't be the right approach... If you want though I would love to help you in any endeavor/steps you want to move forward with this! |
Is the data null because Universal isn't waiting or because it doesn't even open the socket? If the first case, for now, I could grab the master and force Universal to wait - with a mock HTTP req, timeout or sth, until I got the first data? |
@davideast any progress with getting AngularFire2 to play nice with Universal? |
Got around the problem by providing firebase-admin to a FirebaseAdminService, then using that instead of Angularfire2 in a ServerDatabaseModule. Sorry, not a complete example but hope this gives you ideas: https://gist.github.com/funkizer/6d6559787c17a88c60cf2ddc9ca06527 If you're hosting Universal on your own server, you might get away with not getting rid of all Angularfire2 stuff, but at least on Cloud Functions, you'll get ctor is not a constructor or other funny errors or timeouts because injectors fail, so I just got rid of everything related to FB client on server. Key thing is to run firebase-admin related things wrapped in zone.runOutsideAngular(). |
I fixed a similar problem in @ngx-translate/core. Please take a look to my comment I used the cli of babel to compile all js file into es5 - commonjs so that i can use them in nodejs (express) with angular universal --> finally no more SyntaxError: Unexpected token import! |
Any fix for this? |
@davideast what is the timeframe for this? do you need any help with this? SSR is critical for the stuff we are building and I would love to use firebase for it. |
I have Firebase Auth "working" in my starter project here: code: https://github.com/patrickmichalina/fusebox-angular-universal-starter |
I tried to do SSR on Cloud functions with AngularFire2 included. There are no errors and data is fetched from RTDB as it can be seen printed in to the logs. But the html pages never render and soon timeout. @davideast Any updates on the possible fix you mentioned? |
Have same problem here, html pages never render when using AngularFire. @davideast any update? |
I was able to resolve the usage of angularfire2 on server side creating and injecting a "stub" version of AngularFireDatabase that uses the firebase rest api. As @davideast said the problem of timeouts or never render templates is the websocket that never finish and angular do not knows when finish rendering. I didn't even include the angularfire modules on server side. Hope it helps. |
@ncherian @paulogr so the main problem is actually not the socket, but Zone.js, we have a bug in our handling. The microtasks are never allowing appRef isStable to go true, thus Universal never letting go of the rendering until Timeout and even once you do have a rendered page state restoration never happens. If you wrap in a zone.runOutsideAngular() things work. I have on my list to fix. |
There's also no node.js entry to
|
so what should we do ? firebase is very important to me and without SSR to SEO, my angular 2 application is just a toys :( |
@hiepxanh I know its not elegant, nor does it cover all scenarios, but it gets me by until the official supports lands in this library: https://github.com/patrickmichalina/fusebox-angular-universal-starter/blob/master/src/server/server.angular-fire.service.ts |
We use angularfire2 and firestore in our application. Firestore does not render data as @davideast mentioned. From this conversation I understand its going to take time. @hiepxanh you can try other solutions. One which I saw recently is to use chrome's rendertron. Definitely not better than universal. But will work. Check this blog |
Finally Server Side Rendering with Firebase 😊🎉 Introducing AngularFire Lite 🎉AnglularFire Lite is a very very simple library to use Angular with Firebase it supports server-side rendering out of the box for both firebase realtime database and firestore. It renders the SSR app and then switches to the non-SSR to receive real-time updates from firebase with no flickering at all when the angular app bootstraps. Get StartedDemo AppPlease note that this is a personal initiative I started and it's still in very early beta so your help by contributing and supporting the library will be the only way to improve it. |
@hamedbaatour This is really cool! I wish you would have contributed to this project however. We plan on adding support for the rest of the Firebase features soon. I do have one question, is it actually lighter than AngularFire? AngularFire itself is really small, the DB API is 3kb. The Firestore API is 2.3kb. The Auth API is 950 bytes. |
wow, you deserve this 🥇 |
Looking forward to SSR support |
well, without support for socket method from angular. We (angularfire, or anything use socket) cannot work with universal. That really bad news,
|
still looking forward to make my web go production 👍 , event I have dedicated server, when calling to firebase, my data still not render with universal. I can't SEO |
Quick question - can this not be resolved using Cloud apis on server - https://cloud.google.com/firestore/docs/reference/rest/ . With isPlatformBrowser, isPlatformServer can't we control it ? |
are there already results of an AngularFire Lite cooperation? When can we expect SSR in AngularFire? |
@doczoidberg there's a pull request (#1454) for that, so probably soon :) |
"angularfire2": "^5.0.0-rc.6" seems to be working with ssr. Did anything change ? |
@kpsrinivas were you able to make the ssr work with rc.6? |
@andreaaschei yes. |
angularfire2@next has more SSR work, will be cutting RC.7 shortly. Give it
a spin.
…On Fri, Apr 13, 2018, 4:47 AM Srinivas Kolluri ***@***.***> wrote:
@andreaaschei <https://github.com/andreaaschei> yes.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1073 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACvr1oL7Y9a8gjw9Z3CRMN_yqKFRWvnks5toGY8gaJpZM4OZObk>
.
|
Seems to be working with RC.7 although some modifications are needed to the official universal guide if you're using material and other libraries in the server.ts file. Thanks @jamesdaniels and the team at angular firebase for the very helpful video highly recommend checking it out. https://www.youtube.com/watch?v=wij2-gyG12E Still will need to test it further but great job guys! |
SSR in the minimal sense. It still does not have state transfer nor does it have auth. |
We're working on those. This is a nessisary first step and was already a
large change, so we wanted to get out and in people's hands while we work
on state-transfer story (will require a change to the Firebase JS SDK) and
auth (a needed change just landed in the SDK).
…On Thu, Apr 19, 2018, 1:20 PM Patrick Michalina ***@***.***> wrote:
SSR in the minimal sense. It still does not have state transfer nor does
it have auth.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1073 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACvr3fLZcDVzPtJfciP10YUJJyoKRTbks5tqON9gaJpZM4OZObk>
.
|
Has anyone done this? I'm stuck, would love some suggestions, or pointers if I'm missing something obvious or misunderstanding the problem.
Version info
Angular: 4.2.4
Firebase: 4.1.3
AngularFire: 4.0.0-rc1
Firebase-functions: 0.5.9
How to reproduce these conditions
Using AOT compiling, and server-side rendering, as described in this blagpost:
https://medium.com/@evertonrobertoauler/angular-4-universal-app-with-angular-cli-db8b53bba07d
Repo:
https://github.com/SparksNetwork/exp-angular-firebase/tree/shared-code
(note I am working from the
shared-code
branch)(the repo structure is kind of haphazard, everything lives in
/functions
because thats what firebase-functions requires)Steps to set up and reproduce
App runs successfully JIT running
ng serve
.Compile client and server with
ng run build
.Serve via standalone node express server with
ts-node src/server.ts
or via firebase-functions local emulator withfirebase serve --only functions
.Debug output
Diagnosis
I suspect it's choking because the angularfire2 npm module is compiled with es2015 syntax which doesn't work in node (which firebase-functions is based on).
Possible fix?
I don’t know a lot about how NPM works, but I’m wondering if I:
target
and/ormodule
settings in forked tsconfig until I find something that worksnpm install
from my forked angularfire2Only thing I don’t know how to do there is: how do I ensure that my forked angularfire2 gets built? There’s a bunch of stuff in the repo that has to do with the build process that is totally alien to me.
The only other thing I can think of is to try to write my own firebase wrapper for angular,
with blackjack and hookersthat compiles to commonjs. That sounds like an awful idea.Things I’ve Tried
Using DI to swap out AngularFire2 on server
Per the discussion in this thread (angular/universal-starter#127 (comment)), I started writing a fake service that adhered to the angularfire2 interfaces that I could use in my app.server.module.ts. Quickly I realized that because all my services actually have to import from the real angularfire2 module, it still wouldn’t work, because the error gets thrown when the file is imported, not when it’s run.
Copying angularfire2/src into a local lib directory and building it with the project
When I try this, I get all sorts of errors about Zone not being found. I can’t figure out what needs to be included, or how, in order to get it to compile the ts.
The text was updated successfully, but these errors were encountered: