Title: "Unexpected token import" with angularfire2 on angular-cli, AOT, SSR, and firebase-functions · Issue #1073 · angular/angularfire · GitHub
Open Graph Title: "Unexpected token import" with angularfire2 on angular-cli, AOT, SSR, and firebase-functions · Issue #1073 · angular/angularfire
X Title: "Unexpected token import" with angularfire2 on angular-cli, AOT, SSR, and firebase-functions · Issue #1073 · angular/angularfire
Description: 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 ...
Open Graph Description: 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: ...
X Description: 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 Angul...
Opengraph URL: https://github.com/angular/angularfire/issues/1073
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Unexpected token import\" with angularfire2 on angular-cli, AOT, SSR, and firebase-functions","articleBody":"Has anyone done this? I'm stuck, would love some suggestions, or pointers if I'm missing something obvious or misunderstanding the problem.\r\n\r\n### Version info\r\n\r\n**Angular:** 4.2.4\r\n\r\n**Firebase:** 4.1.3\r\n\r\n**AngularFire:** 4.0.0-rc1\r\n\r\n**Firebase-functions:** 0.5.9\r\n\r\n### How to reproduce these conditions\r\n\r\nUsing AOT compiling, and server-side rendering, as described in this blagpost:\r\nhttps://medium.com/@evertonrobertoauler/angular-4-universal-app-with-angular-cli-db8b53bba07d\r\n\r\nRepo:\r\nhttps://github.com/SparksNetwork/exp-angular-firebase/tree/shared-code\r\n(note I am working from the `shared-code` branch)\r\n(the repo structure is kind of haphazard, everything lives in `/functions` because thats what firebase-functions requires)\r\n\r\n**Steps to set up and reproduce**\r\n\r\nApp runs successfully JIT running `ng serve`.\r\n\r\nCompile client and server with `ng run build`.\r\n\r\nServe via standalone node express server with `ts-node src/server.ts` or via firebase-functions local emulator with `firebase serve --only functions`.\r\n\r\n### Debug output\r\n\r\n```\r\nFirebaseError: Error occurred while parsing your function triggers.\r\n\r\n/Users/sdebaun/exp-angular-firebase/functions/node_modules/angularfire2/app/firebase.app.module.js:1\r\n(function (exports, require, module, __filename, __dirname) { import { InjectionToken, } from '@angular/core';\r\n ^^^^^^\r\nSyntaxError: Unexpected token import\r\n at createScript (vm.js:53:10)\r\n at Object.runInThisContext (vm.js:95:10)\r\n at Module._compile (module.js:543:28)\r\n at Object.Module._extensions..js (module.js:580:10)\r\n at Module.load (module.js:488:32)\r\n at tryModuleLoad (module.js:447:12)\r\n at Function.Module._load (module.js:439:3)\r\n at Module.require (module.js:498:17)\r\n at require (internal/module.js:20:19)\r\n at Object.\u003canonymous> (/Users/sdebaun/exp-angular-firebase/functions/fn/dist/dist/ngfactory/src/app/app.server.module.ngfactory.js:23:13)\r\ni functions: No HTTPS functions emulated. Support for other function types are coming soon.\r\n```\r\n\r\n# Diagnosis\r\n\r\nI 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).\r\n\r\n# Possible fix?\r\n\r\nI don’t know a lot about how NPM works, but I’m wondering if I:\r\n1. Fork angularfire2\r\n2. change the `target` and/or `module` settings in forked tsconfig until I find something that works\r\n3. in my app, `npm install` from my forked angularfire2\r\n\r\nOnly 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.\r\n\r\nThe only other thing I can think of is to try to write my own firebase wrapper for angular, ~~with blackjack and hookers~~ that compiles to commonjs. That sounds like an awful idea.\r\n\r\n# Things I’ve Tried\r\n\r\n## Using DI to swap out AngularFire2 on server\r\n\r\nPer the discussion in this thread (https://github.com/angular/universal-starter/issues/127#issuecomment-287644140), 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.\r\n\r\n## Copying angularfire2/src into a local lib directory and building it with the project\r\n\r\nWhen 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.\r\n\r\n","author":{"url":"https://github.com/sdebaun","@type":"Person","name":"sdebaun"},"datePublished":"2017-07-16T07:37:58Z","url":"https://github.com/angular/angularfire/issues/1073"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:59d709d9-e328-a384-a0e3-0e94d04a1ad3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C1D6:1E74B0:7F8CFF:A20734:6B035C1F |
| html-safe-nonce | 693397bdfba3880ee4f4aab220d2eeb40a7ae7561aad7ad6619e909a3cc82140 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMUQ2OjFFNzRCMDo3RjhDRkY6QTIwNzM0OjZCMDM1QzFGIiwidmlzaXRvcl9pZCI6IjIxNzg5Mjc5NjQzNjI4NTc1MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 19367e462414df525ee05b1a1a92191bcbc44c05b82d2b79bd00abd2eea47b11 |
| hovercard-subject-tag | issue:243223431 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angularfire/1073/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ea180dd45da50b1354d2c9fd7c90f1abf65848687c589120e5ae397a8d29006/angular/angularfire/issues/1073 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ea180dd45da50b1354d2c9fd7c90f1abf65848687c589120e5ae397a8d29006/angular/angularfire/issues/1073 |
| og:image:alt | 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: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sdebaun |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angularfire git https://github.com/angular/angularfire.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 49453413 |
| octolytics-dimension-repository_nwo | angular/angularfire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49453413 |
| octolytics-dimension-repository_network_root_nwo | angular/angularfire |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width