2

I'm trying to use Firebase's Cloud Firestore from a preact-cli generated project but have been caught at the first hurdle. I chose Firebase's v9 SDK, that's in beta, to get ahead of the curve (but maybe that was a mistake). When building, there's an error from a Firebase SDK file but I'm not sure if it's caused by the SDK itself, babel, webpack, preact-cli or a combination. I also don't know how to go about diagnosing it, since I'm new to these tools.

Steps below, any ideas what the cause of this error might be?

npx preact-cli create typescript webapp
npm install --save firebase@9.0.0-beta.1

Then in src/components/app.tsx, make use of the Firestore SDK by adding

import { getFirestore } from "firebase/firestore";
getFirestore();

But the build fails.

$ npm run build

> webapp@0.0.0 build
> preact build

 Build  [==                  ] 12% (1.3s) building(13200:6) switch-case fall-through not supported - added break. See https://github.com/MatAtBread/nodent#differences-from-the-es7-specification
[BABEL] Note: The code generator has deoptimised the styling of ../node_modules/@firebase/firestore/dist/exp/index.browser.esm2017.js as it exceeds the max of 500KB.
✖ ERROR ../node_modules/@firebase/firestore/dist/exp/index.browser.esm2017.js 5055:431
Module parse failed: Unsyntactic break (5055:431)
File was processed with these loaders:
 * ../node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
(Source code omitted for this binary file)
 @ ../node_modules/firebase/firestore/dist/index.esm.js 1:0-36 1:0-36
 @ ./components/app.tsx
 @ ./index.ts
DrYap
  • 6,525
  • 2
  • 31
  • 54
  • This does appear to be a potential bug, I would suggest using the working web8 version. upgrading is fairly easy if needed. it is certainly some problem with Babel and how it's trying to compile Firestore, could potentially be solved with a config setting – DIGI Byte May 01 '21 at 22:45
  • specifically, the error appears to be on a switch that is relying on fall-through – DIGI Byte May 01 '21 at 22:48
  • @DIGIByte It's not a bug, the error gives a URL. `nodent` doesn't support switch-case fall through, and `preact-cli` uses `nodent`. OP, you can try to get the maintainers of firebase to change this, but it's not really a bug. It's a feature that's known to not be supported, as following that URL would tell you. – rschristian May 02 '21 at 00:01
  • I said potentially because there should either be config options to ignore this case and could have been an oversight or on purpose. it's really down to opinion from different developers. – DIGI Byte May 02 '21 at 07:32
  • 2
    It looks like a bug in nodent-transform to me, used by the fast-async babel plugin that preact-cli selects. Line 13200 is a switch case with a break, but it's wrapped in braces. I've avoided the error in two ways: 1) removing the braces 2) hackily fixing nodent-transform to look inside the block. – DrYap May 02 '21 at 08:10
  • @DrYap I'm having the same issue, did you find a solution? And if so, would you like to share it? – hesselbom Jun 14 '21 at 09:31
  • Created a bug report, feel free to +1 it https://github.com/preactjs/preact-cli/issues/1591 – Jakša Mališić Aug 17 '21 at 04:29

0 Answers0